NAME

Catalyst::Plugin::Widget - Simple way to create reusable HTML fragments

VERSION

Version 0.04

DESCRIPTION

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.

SYNOPSIS

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 %]

METHODS

widget

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

AUTHOR

Oleg A. Mamontov, <oleg at mamontov.net>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Catalyst::Plugin::Widget

You can also look for information at:

LICENSE AND COPYRIGHT

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.