| HTML-Shakan documentation | Contained in the HTML-Shakan distribution. |
HTML::Shakan::Declare - declare the form
# 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;
}
This module supports to generate form using declare style.
This module exports HTML::Shakan::Fields's exported functions and following functions.
Register new form named $name with <\@fields>.
Now, your form class provides get method. This method returns instance of HTML::Shakan.
Tokuhiro Matsuno
| 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__