Catalyst::Plugin::Widget - Simple way to create reusable HTML fragments
Version 0.04
Termin widget means kind of object that knows about current Catalyst context and can be easily stringified to text representation.
A typical example of a widget - CatalystX::Widget::Paginator module.
Setup plugin:
use Catalyst( qw( Widget ) );
Create custom widget class:
package MyApp::Widget::Greeting; use Moose; extends 'Catalyst::Plugin::Widget::Base'; has nobody => ( is => 'rw', default => "Sorry, what's your name?" ); sub render { my $self = shift; $self->context->can('user_exists') && $self->context->user_exists ? 'Hello, ' . $self->context->user->name : $self->nobody; } 1;
Create widget instance in controller>:
sub index :Path :Args(0) { my ( $self,$c ) = @_; my $w = $c->widget('~Greeting'); $c->stash( greet => $w ); }
Place widget onto template:
From auth: [% greet %]
Create instance of widget class. Class name is handled by the following rules:
- starting with the '+': use the entire name (except '+' sign)
- starting with the '~': use name (except '~' sign) prepended with application class name and '::Widget::'.
- other: use name prepended with application config parameter $config->{ widget }{ default_namespace } or string 'CatalystX::Widget::'
Examples:
$c->widget('+Some::Class'); # Some::Class $c->widget('~Class'); # App::Widget::Class $c->widget('Class'); # CatalystX::Widget::Class App->config{ widget }{ default_namespace } = 'Local'; $c->widget('Class'); # Local::Class
Oleg A. Mamontov, <oleg at mamontov.net>
<oleg at mamontov.net>
Please report any bugs or feature requests to bug-catalyst-plugin-widget at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-Widget. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-catalyst-plugin-widget at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Catalyst::Plugin::Widget
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-Widget
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Catalyst-Plugin-Widget
CPAN Ratings
http://cpanratings.perl.org/d/Catalyst-Plugin-Widget
Search CPAN
http://search.cpan.org/dist/Catalyst-Plugin-Widget/
Copyright 2010 Oleg A. Mamontov.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Catalyst::Plugin::Widget, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Plugin::Widget
CPAN shell
perl -MCPAN -e shell install Catalyst::Plugin::Widget
For more information on module installation, please visit the detailed CPAN module installation guide.