Catalyst::Plugin::HTML::Widget - HTML Widget And Validation Framework


Catalyst-Plugin-HTML-Widget documentation Contained in the Catalyst-Plugin-HTML-Widget distribution.

Index


Code Index:

NAME

Top

Catalyst::Plugin::HTML::Widget - HTML Widget And Validation Framework

SYNOPSIS

Top

    use Catalyst qw/HTML::Widget;

    $c->widget('foo')->method('get')->action('/foo/action');

    $c->widget('foo')->element( 'Textfield', 'age' )->label('Age')->size(3);
    $c->widget('foo')->element( 'Textfield', 'name' )->label('Name')->size(60);
    $c->widget('foo')->element( 'Submit', 'ok' )->value('OK');

    $c->widget('foo')->constraint( 'Integer', 'age' )->message('No integer.');
    $c->widget('foo')->constraint( 'All', 'age', 'name' )
        ->message('Missing value.');

    $c->widget( HTML::Widget->new('foo') );

    $c->widget('foo')->indicator('some_field');

    my $result = $c->widget('foo')->process;
    my $result = $c->widget('foo')->process($query);

    my $result = $c->widget_result('foo');      #  with query params

DESCRIPTION

Top

HTML Widget And Validation Framework.

METHODS

Top

$c->widget( $name, $widget )

Returns a HTML::Widget. If no object exists, it will be created on the fly. The widget name defaults to _widget.

$c->widget_result($name)

Returns a HTML::Widget::Result object, processed with query and upload parameters.

SEE ALSO

Top

Catalyst, HTML::Widget

AUTHOR

Top

Sebastian Riedel, sri@oook.de

LICENSE

Top

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.


Catalyst-Plugin-HTML-Widget documentation Contained in the Catalyst-Plugin-HTML-Widget distribution.
package Catalyst::Plugin::HTML::Widget;

use warnings;
use strict;
use HTML::Widget;

our $VERSION = '1.1';

sub widget {
    my ( $c, $name, $widget ) = @_;
    $widget = $name if ref $name;
    $c->{_widget} ||= {};
    $name ||= $widget ? $widget->name ? $widget->name : '_widget' : '_widget';
    $c->{_widget}->{$name} ||= ( $widget || HTML::Widget->new($name) );
    return $c->{_widget}->{$name};
}

sub widget_result {
    my $c = shift;
    my $w = $c->widget(@_);

    my $result;
    my $indi = $w->indicator;
    $indi = ref $indi ? $indi : sub { $c->request->param( $w->indicator ) };
    if ( $indi->() ) {
        local $w->{query}   = $c->request;
        local $w->{uploads} = $c->request->uploads;
        $result = $w->result;
    }
    else {
        local $w->{query}   = undef;
        local $w->{uploads} = undef;
        $result = $w->result;
    }

    return $result;
}

1;