blib/lib/HTML/Shakan/Fields.pm

filter: Statementstmt 100% 29 / 29 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 100% 11 / 11 totaltotal 98.2% 57 / 58 CC 2 SCAR 1.1
CC
2
Cov
97%
Duplication
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/HTML/Shakan/Field.pm ↑ Summary blib/lib/HTML/Shakan/Field/File.pm »
1 package HTML::Shakan::Fields;
2 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 22 our @EXPORT = qw(
8 TextField
9 EmailField
10 URLField
11 UIntField
12 IntField
13  
14 PasswordField
15  
16 FileField
17 ImageField
18  
19 ChoiceField
20  
21 DateField
22  
23 Duplication
24 );
25  
26 # DateTimeField
27 # ImageField
28 # TimeField
29  
30 sub _input {
31 41 ▶ HTML::Shakan::Field::Input->new( @_ );
Subroutine _input: called CC=1 SCAR=0.0
32 }
33  
34 sub TextField {
35 38 ▶ _input(type => 'text', @_);
Subroutine TextField: called CC=1 SCAR=0.0
Pod documented
36 }
37  
38 sub EmailField {
39 2 ▶ TextField(@_)->add_constraint('EMAIL_LOOSE');
Subroutine EmailField: called CC=1 SCAR=0.0
Pod documented
40 }
41  
42 sub URLField {
43 2 ▶ TextField(@_)->add_constraint('HTTP_URL');
Subroutine URLField: called CC=1 SCAR=0.0
Pod documented
44 }
45  
46 sub UIntField {
47 2 ▶ TextField(@_)->add_constraint('UINT');
Subroutine UIntField: called CC=1 SCAR=0.0
Pod documented
48 }
49  
50 sub IntField {
51 2 ▶ TextField(@_)->add_constraint('INT');
Subroutine IntField: called CC=1 SCAR=0.0
Pod documented
52 }
53  
54 sub PasswordField {
55 3 ▶ _input(type => 'password', @_);
Subroutine PasswordField: called CC=1 SCAR=0.0
Pod documented
56 }
57  
58 sub FileField {
59 8 ▶ HTML::Shakan::Field::File->new(@_);
Subroutine FileField: called CC=1 SCAR=0.0
Pod documented
60 }
61  
62 sub ImageField {
63 3 ▶ FileField(@_)->add_constraint(['FILE_MIME' => qr{image/.+}]);
Subroutine ImageField: called CC=1 SCAR=0.0
Pod documented
64 }
65  
66 sub ChoiceField {
67 13 ▶ HTML::Shakan::Field::Choice->new( @_ );
Subroutine ChoiceField: called CC=1 SCAR=0.0
Pod documented
68 }
69  
70 sub DateField {
71 4 ▶ HTML::Shakan::Field::Date->new( @_ );
Subroutine DateField: called CC=1 SCAR=0.0
Pod documented
72 }
73  
74 sub Duplication {
75 2 ▶ my ($name, $f1, $f2) = @_;
Subroutine Duplication: called CC=2 SCAR=7.0
Pod documented
76 2 ▶ Carp::croak('missing args. Usage: Duplication(name, field1, field2)') unless @_ == 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 2 2
77 2 $f1->add_complex_constraint(
78 +{ $name => [ $f1->name(), $f2->name() ] } => [ 'DUPLICATION' ]
79 );
80 2 return ($f1, $f2);
81 }
82  
83 22 1;
84 __END__
85  
86 =encoding utf8
87  
88 =head1 NAME
89  
90 HTML::Shakan::Fields - fields
91  
92 =head1 DESCRIPTION
93  
94 This module exports some functions, that generates a instance of HTML::Field::*.
95  
96 If you want to know the details, please look the source :)
97  
98 =head1 FUNCTIONS
99  
100 =over 4
101  
102 =item C<< TextField(name => 'foo') >>
103  
104 create a instance of HTML::Shakan::Input.
105  
106 This is same as HTML::Shakan::Input->new(name => 'foo', type => 'text', @_);
107  
108 =item C<< EmailField(name => 'email') >>
109  
110 TextField() + EMAIL_LOOSE constraint.
111  
112 =item C<< URLField(name => 'url') >>
113  
114 TextField() + HTTP_URL constraint
115  
116 =item C<< UIntField(name => 'i') >>
117  
118 TextField() + UINT constraint
119  
120 =item C<< IntField(name => 'i') >>
121  
122 TextField() + INT constraint
123  
124 =item C<< PasswordField(name => 'pw') >>
125  
126 define <input type="password" /> field
127  
128 =item C<< FileField(name => 'file') >>
129  
130 define <input type="file" /> field
131  
132 =item C<< ImageField(name => 'image') >>
133  
134 FileField + FILE_MIME=image/* constraint
135  
136 =item C<< ChoiceField(name => 'interest', choices => [1 => 'moose', 2 => 'mouse', 3 => 'exporter']) >>
137  
138 selector field.
139  
140 =item C<< DateField(name => 'birthdate') >>
141  
142 date input field.
143  
144 =item C<< Duplication('mail' => EmailField(), EmailField()) >>
145  
146 both field contains same value?
147  
148 =back
149  
150 =head1 AUTHORS
151  
152 Tokuhiro Matsuno(tokuhirom)
153  
154 =head1 SEE ALSO
155  
156 L<HTML::Shakan>
157  
158 use Params::Validate ':all';
« blib/lib/HTML/Shakan/Field.pm ↑ Summary blib/lib/HTML/Shakan/Field/File.pm »