Catalyst-Plugin-Widget

 view release on metacpan or  search on metacpan

lib/Catalyst/Plugin/Widget.pm  view on Meta::CPAN

package Catalyst::Plugin::Widget;

=head1 NAME

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

=head1 VERSION

Version 0.04

=cut

our $VERSION = '0.04';

use strict;
use warnings qw(all);


=head1 DESCRIPTION

Termin I<widget> means kind of object that knows about current L<Catalyst>
context and can be easily stringified to text representation.

A typical example of a widget - L<CatalystX::Widget::Paginator> module.


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





( run in 0.665 second using v1.01-cache-2.11-cpan-364913b4093 )