HTML::Shakan::Declare - declare the form


HTML-Shakan documentation Contained in the HTML-Shakan distribution.

Index


Code Index:

NAME

Top

HTML::Shakan::Declare - declare the form

SYNOPSIS

Top

    # declare
    {
        package My::Form;
        use HTML::Shakan::Declare;

        form 'add' => (
            TextField(
                name     => 'name',
                required => 1,
            ),
            TextField(
                name     => 'email',
                required => 1,
            ),
        );
    }

    # use it
    {
        my $form = My::Form->get(
            'add' => (
                request => CGI->new,
            )
        );
        $form->render;
    }

DESCRIPTION

Top

This module supports to generate form using declare style.

FUNCTIONS

Top

This module exports HTML::Shakan::Fields's exported functions and following functions.

form($name, \@fields)

Register new form named $name with <\@fields>.

EXPORTED METHODS

Top

Your::Form::Class->get($name[, %args])

Now, your form class provides get method. This method returns instance of HTML::Shakan.

AUTHORS

Top

Tokuhiro Matsuno

SEE ALSO

Top

HTML::Shakan


HTML-Shakan documentation Contained in the HTML-Shakan distribution.

package HTML::Shakan::Declare;
use strict;
use warnings;
use parent 'Exporter';
use HTML::Shakan ();

our @EXPORT = qw(form get);

sub import {
    my $class = shift;
    __PACKAGE__->export_to_level(1);
    HTML::Shakan::Fields->export_to_level(1);
}

our $FORMS;
sub form ($@) { ## no critic.
    my ($name, @fields) = @_;
    my $pkg = caller(0);
    $FORMS->{$pkg}->{$name} = \@fields;
}

sub get {
    my ($class, $name, %args) = @_;
    $class = ref $class || $class;
    return HTML::Shakan->new(
        fields => $FORMS->{$class}->{$name},
        %args,
    );
}

1;
__END__