line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Shakan::Field; |
2
|
23
|
|
|
23
|
|
8422
|
use strict; |
|
23
|
|
|
|
|
52
|
|
|
23
|
|
|
|
|
564
|
|
3
|
23
|
|
|
23
|
|
113
|
use warnings; |
|
23
|
|
|
|
|
43
|
|
|
23
|
|
|
|
|
487
|
|
4
|
23
|
|
|
23
|
|
102
|
use Mouse; |
|
23
|
|
|
|
|
50
|
|
|
23
|
|
|
|
|
110
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has id => ( |
7
|
|
|
|
|
|
|
is => 'rw', |
8
|
|
|
|
|
|
|
isa => 'Str', |
9
|
|
|
|
|
|
|
trigger => sub { |
10
|
|
|
|
|
|
|
my ($self, $id) = @_; |
11
|
|
|
|
|
|
|
$self->{attr}->{id} = $id; |
12
|
|
|
|
|
|
|
}, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has name => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
isa => 'Str', |
18
|
|
|
|
|
|
|
required => 1, |
19
|
|
|
|
|
|
|
trigger => sub { |
20
|
|
|
|
|
|
|
my ( $self, $name ) = @_; |
21
|
|
|
|
|
|
|
$self->{attr}->{name} = $name; |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has value => ( |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
isa => 'Str', |
28
|
|
|
|
|
|
|
required => 0, |
29
|
|
|
|
|
|
|
trigger => sub { |
30
|
|
|
|
|
|
|
my ( $self, $value ) = @_; |
31
|
|
|
|
|
|
|
$self->{attr}->{value} = $value; |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has filters => ( |
36
|
|
|
|
|
|
|
is => 'rw', |
37
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
38
|
|
|
|
|
|
|
default => sub { +[] } |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has widget => ( |
42
|
|
|
|
|
|
|
is => 'ro', |
43
|
|
|
|
|
|
|
isa => 'Str', |
44
|
|
|
|
|
|
|
required => 1, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has attr => ( |
48
|
|
|
|
|
|
|
is => 'ro', |
49
|
|
|
|
|
|
|
isa => 'HashRef', |
50
|
|
|
|
|
|
|
lazy => 1, |
51
|
|
|
|
|
|
|
default => sub { |
52
|
|
|
|
|
|
|
+{} |
53
|
|
|
|
|
|
|
}, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has label => ( |
57
|
|
|
|
|
|
|
is => 'ro', |
58
|
|
|
|
|
|
|
isa => 'Str', |
59
|
|
|
|
|
|
|
lazy => 1, |
60
|
|
|
|
|
|
|
default => sub { shift->name } |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
has label_class => ( |
64
|
|
|
|
|
|
|
is => 'ro', |
65
|
|
|
|
|
|
|
isa => 'Str', |
66
|
|
|
|
|
|
|
predicate => 'has_label_class', |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
has required => ( |
70
|
|
|
|
|
|
|
is => 'ro', |
71
|
|
|
|
|
|
|
isa => 'Bool', |
72
|
|
|
|
|
|
|
default => 0, |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
has inflator => ( |
76
|
|
|
|
|
|
|
is => 'ro', |
77
|
|
|
|
|
|
|
isa => 'Object', |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
has custom_validation => ( |
81
|
|
|
|
|
|
|
is => 'ro', |
82
|
|
|
|
|
|
|
isa => 'CodeRef', |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
has constraints => ( |
86
|
|
|
|
|
|
|
is => 'ro', |
87
|
|
|
|
|
|
|
isa => 'ArrayRef', |
88
|
|
|
|
|
|
|
default => sub { +[] }, |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub add_constraint { |
92
|
15
|
|
|
15
|
0
|
43
|
my ($self, @constraint) = @_; |
93
|
15
|
|
|
|
|
29
|
push @{$self->{constraints}}, @constraint; |
|
15
|
|
|
|
|
35
|
|
94
|
15
|
|
|
|
|
113
|
$self; # method chain |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
has complex_constraints => ( |
98
|
|
|
|
|
|
|
is => 'ro', |
99
|
|
|
|
|
|
|
isa => 'ArrayRef', |
100
|
|
|
|
|
|
|
default => sub { +[] }, |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub add_complex_constraint { |
104
|
2
|
|
|
2
|
0
|
6
|
my ($self, @constraints) = @_; |
105
|
2
|
|
|
|
|
3
|
push @{$self->{complex_constraints}}, @constraints; |
|
2
|
|
|
|
|
6
|
|
106
|
2
|
|
|
|
|
5
|
$self; # method chain |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub get_constraints { |
110
|
68
|
|
|
68
|
0
|
199
|
my $self = shift; |
111
|
|
|
|
|
|
|
|
112
|
68
|
|
|
|
|
109
|
my @rule = @{$self->{constraints}}; |
|
68
|
|
|
|
|
205
|
|
113
|
68
|
100
|
|
|
|
276
|
if ($self->required) { |
114
|
15
|
|
|
|
|
38
|
push @rule, 'NOT_NULL'; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
return ( |
117
|
|
|
|
|
|
|
$self->name => \@rule, |
118
|
68
|
|
|
|
|
178
|
@{ $self->complex_constraints }, |
|
68
|
|
|
|
|
309
|
|
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
23
|
|
|
23
|
|
15984
|
no Mouse; |
|
23
|
|
|
|
|
59
|
|
|
23
|
|
|
|
|
95
|
|
123
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
124
|
|
|
|
|
|
|
__END__ |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=encoding utf8 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=for stopwords attr |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 NAME |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
HTML::Shakan::Field - base class for field object |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 DESCRIPTION |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This is a base class for filed object. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=over 4 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item id |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
the 'id' attribute for the HTML elements. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item name |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
the 'name' attribute for the HTML elements. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item value |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
the 'value' attribute for the HTML elements. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item filters: ArrayRef[Str] |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This is parameter filters in arrayref. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
For example, following field removes white space from parameter value in head and end. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
TextField( |
161
|
|
|
|
|
|
|
name => 'f', |
162
|
|
|
|
|
|
|
required => 1, |
163
|
|
|
|
|
|
|
filters => [qw'WhiteSpace'] |
164
|
|
|
|
|
|
|
), |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item widget |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
type of widget. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item attr |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
hashref about the miscellaneous attributes. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item label |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
label for this field. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item label_class |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
class attribute for this field's label. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item required |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
is this field's value required? |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item custom_validation |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
TextField( |
189
|
|
|
|
|
|
|
name => 'id', |
190
|
|
|
|
|
|
|
custom_validation => sub { |
191
|
|
|
|
|
|
|
my ($form, $field) = @_; |
192
|
|
|
|
|
|
|
if (is_reserved_id($form->param($field->name))) { |
193
|
|
|
|
|
|
|
$form->set_error($field->name() => 'reserved'); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
) |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
You can register custom validation callback. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
The callback function takes two arguments. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=over 4 |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item $form |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
This is a instance of L<HTML::Shakan>. You can take query parameter value by this object. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item $field |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
The field object itself. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=back |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item constraints |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
constraints for FormValidator::Lite. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=back |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 AUTHORS |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
tokuhirom |
223
|
|
|
|
|
|
|
|