| 1 | package HTML::Shakan::Declare; | ||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use parent 'Exporter'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use HTML::Shakan (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 2 | our @EXPORT = qw(form get); | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | sub import { | ||||||||||||||||||||
| 10 | 2 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | __PACKAGE__->export_to_level(1); | |||||||||||||||||||
| 12 | 2 | HTML::Shakan::Fields->export_to_level(1); | |||||||||||||||||||
| 13 | } | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | our $FORMS; | |||||||||||||||||||
| 16 | sub form ($@) { ## no critic. | ||||||||||||||||||||
| 17 | 2 | ▶ | my ($name, @fields) = @_; | ||||||||||||||||||
|
Subroutine
form: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 18 | 2 | my $pkg = caller(0); | |||||||||||||||||||
| 19 | 2 | $FORMS->{$pkg}->{$name} = \@fields; | |||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | sub get { | ||||||||||||||||||||
| 23 | 3 | ▶ | my ($class, $name, %args) = @_; | ||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 24 | 3 | ▶ | $class = ref $class || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 25 | return HTML::Shakan->new( | ||||||||||||||||||||
| 26 | 3 | fields => $FORMS->{$class}->{$name}, | |||||||||||||||||||
| 27 | %args, | ||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 2 | 1; | |||||||||||||||||||
| 32 | __END__ | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =head1 NAME | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | HTML::Shakan::Declare - declare the form | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =head1 SYNOPSIS | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | # declare | ||||||||||||||||||||
| 41 | { | ||||||||||||||||||||
| 42 | package My::Form; | ||||||||||||||||||||
| 43 | use HTML::Shakan::Declare; | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | form 'add' => ( | ||||||||||||||||||||
| 46 | TextField( | ||||||||||||||||||||
| 47 | name => 'name', | ||||||||||||||||||||
| 48 | required => 1, | ||||||||||||||||||||
| 49 | ), | ||||||||||||||||||||
| 50 | TextField( | ||||||||||||||||||||
| 51 | name => 'email', | ||||||||||||||||||||
| 52 | required => 1, | ||||||||||||||||||||
| 53 | ), | ||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | # use it | ||||||||||||||||||||
| 58 | { | ||||||||||||||||||||
| 59 | my $form = My::Form->get( | ||||||||||||||||||||
| 60 | 'add' => ( | ||||||||||||||||||||
| 61 | request => CGI->new, | ||||||||||||||||||||
| 62 | ) | ||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||
| 64 | $form->render; | ||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | =head1 DESCRIPTION | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | This module supports to generate form using declare style. | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =head1 FUNCTIONS | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | This module exports L<HTML::Shakan::Fields>'s exported functions and following functions. | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | =over 4 | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | =item form($name, \@fields) | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | Register new form named I<$name> with C<<\@fields>>. | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | =back | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =head1 EXPORTED METHODS | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | =over 4 | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =item Your::Form::Class->get($name[, %args]) | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | Now, your form class provides I< get > method. This method returns instance of L<HTML::Shakan>. | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =back | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | =head1 AUTHORS | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | Tokuhiro Matsuno | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =head1 SEE ALSO | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | L<HTML::Shakan> | ||||||||||||||||||||
| 100 | |||||||||||||||||||||