line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormStructure::Query; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
15
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
78
|
|
4
|
2
|
|
|
2
|
|
12
|
use base qw(Class::Accessor); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2167
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(&_my_accessors); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub _init { |
9
|
10
|
|
|
10
|
|
11
|
my $opt = shift; |
10
|
10
|
50
|
|
|
|
31
|
$opt->{query_accessors} = defined $opt->{query_accessors} ? |
11
|
|
|
|
|
|
|
$opt->{query_accessors} : []; |
12
|
10
|
|
|
|
|
39
|
__PACKAGE__->mk_accessors( |
13
|
10
|
|
|
|
|
18
|
&_my_accessors,@{$opt->{query_accessors}} |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub _my_accessors { |
18
|
12
|
|
|
12
|
|
70
|
return qw(name type value checked selected |
19
|
|
|
|
|
|
|
more less be consist consistf store storef |
20
|
|
|
|
|
|
|
column error |
21
|
|
|
|
|
|
|
tag_label tag_attr tag_desc |
22
|
|
|
|
|
|
|
tag_val_label tag_left_in tag_right_in |
23
|
|
|
|
|
|
|
scratch); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
10
|
|
|
10
|
1
|
13
|
my $class = shift; |
28
|
10
|
|
|
|
|
12
|
my $query = shift; |
29
|
10
|
|
|
|
|
13
|
my $opt = shift; |
30
|
10
|
|
|
|
|
99
|
_init($opt); |
31
|
10
|
|
|
|
|
6412
|
my $self = bless { _query => $query }, $class; |
32
|
10
|
|
|
|
|
15
|
$self->$_($query->{$_}) for (keys %{$query}); |
|
10
|
|
|
|
|
59
|
|
33
|
10
|
|
|
|
|
544
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub array_of { |
37
|
49
|
|
|
49
|
0
|
71
|
my $self = shift; |
38
|
49
|
|
|
|
|
75
|
my $meth = shift; |
39
|
49
|
100
|
|
|
|
118
|
return unless defined $self->$meth(); |
40
|
25
|
50
|
|
|
|
234
|
my $array = defined $self->$meth() ? $self->$meth() : []; |
41
|
25
|
|
|
|
|
367
|
return @{$array}; |
|
25
|
|
|
|
|
87
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _compare_value_with_arg { |
45
|
14
|
|
|
14
|
|
15
|
my $self = shift; |
46
|
14
|
|
|
|
|
15
|
my $meth = shift; |
47
|
14
|
|
|
|
|
15
|
my $arg = shift; |
48
|
14
|
100
|
|
|
|
35
|
return unless defined $self->$meth(); |
49
|
3
|
|
|
|
|
27
|
my $ret = ''; |
50
|
3
|
100
|
|
|
|
7
|
if (ref $self->$meth() eq 'ARRAY') { |
51
|
1
|
|
|
|
|
9
|
for (@{$self->$meth()}) { |
|
1
|
|
|
|
|
3
|
|
52
|
3
|
100
|
|
|
|
19
|
$ret = $meth if $arg eq $_; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
2
|
100
|
|
|
|
19
|
$ret = $meth if $arg eq $self->$meth(); |
57
|
|
|
|
|
|
|
} |
58
|
3
|
|
|
|
|
24
|
return $ret; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub is_checked { |
62
|
7
|
|
|
7
|
0
|
221
|
my $self = shift; |
63
|
7
|
|
|
|
|
9
|
my $arg = shift; |
64
|
7
|
|
|
|
|
14
|
$self->_compare_value_with_arg('checked',$arg); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub is_selected { |
68
|
7
|
|
|
7
|
0
|
62
|
my $self = shift; |
69
|
7
|
|
|
|
|
42
|
my $arg = shift; |
70
|
7
|
|
|
|
|
14
|
$self->_compare_value_with_arg('selected',$arg); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub column_name { |
74
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
75
|
0
|
0
|
|
|
|
0
|
if ($self->column == 1) { |
76
|
0
|
|
|
|
|
0
|
return $self->name; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { |
79
|
0
|
|
|
|
|
0
|
return $self->column; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub store_error { |
84
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
85
|
0
|
|
0
|
|
|
0
|
my $error = $self->error || []; |
86
|
0
|
|
|
|
|
0
|
push @{$error}, shift; |
|
0
|
|
|
|
|
0
|
|
87
|
0
|
|
|
|
|
0
|
$self->error($error); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
14
|
|
|
14
|
0
|
158
|
sub add { shift->add_right(@_) } |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub add_left { |
93
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
94
|
0
|
|
|
|
|
0
|
my ($key,$val) = @_; |
95
|
0
|
|
|
|
|
0
|
$self->_do_add($key,$val,1); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub add_right { |
99
|
14
|
|
|
14
|
0
|
17
|
my $self = shift; |
100
|
14
|
|
|
|
|
18
|
my ($key,$val) = @_; |
101
|
14
|
|
|
|
|
26
|
$self->_do_add($key,$val); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _do_add { |
105
|
14
|
|
|
14
|
|
16
|
my $self = shift; |
106
|
14
|
|
|
|
|
18
|
my ($key,$val,$left) = @_; |
107
|
14
|
100
|
|
|
|
31
|
my $stored = defined $self->$key() ? $self->$key() : ''; |
108
|
14
|
50
|
|
|
|
170
|
if ($left) { |
109
|
0
|
0
|
|
|
|
0
|
if (ref $stored) { |
110
|
0
|
0
|
|
|
|
0
|
push @{$self->$key()}, $val if ref $stored eq 'ARRAY'; |
|
0
|
|
|
|
|
0
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
else { |
113
|
0
|
|
|
|
|
0
|
$self->$key($stored . $self->$key()); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
else { |
117
|
14
|
50
|
|
|
|
24
|
if (ref $stored) { |
118
|
0
|
0
|
|
|
|
0
|
unshift @{$self->$key()}, $val if ref $stored eq 'ARRAY'; |
|
0
|
|
|
|
|
0
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else { |
121
|
14
|
|
|
|
|
48
|
$self->$key($stored . $val); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub tag { |
130
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
131
|
0
|
|
0
|
|
|
|
my $tag = shift || ''; |
132
|
0
|
0
|
|
|
|
|
if ($self->type =~ /^(?:text|password|file|hidden)$/i) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$tag = $self->_Input; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
elsif ($self->type =~ /radio|checkbox/i) { |
136
|
0
|
|
|
|
|
|
$tag = $self->_RadioCheckbox; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
elsif ($self->type =~ /select/i) { |
139
|
0
|
|
|
|
|
|
$tag = $self->_Select; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
elsif ($self->type =~ /textarea/i) { |
142
|
0
|
|
|
|
|
|
$tag = $self->_Textarea; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub _Input { |
147
|
0
|
|
|
0
|
|
|
my $self = shift; |
148
|
0
|
|
|
|
|
|
return sprintf qq|%s%s|,( |
149
|
|
|
|
|
|
|
$self->tag_left_in, |
150
|
|
|
|
|
|
|
$self->name,$self->type,$self->value,$self->tag_attr, |
151
|
|
|
|
|
|
|
$self->tag_right_in, |
152
|
|
|
|
|
|
|
); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub _Select { |
156
|
0
|
|
|
0
|
|
|
my $self = shift; |
157
|
0
|
|
|
|
|
|
my $start = sprintf qq|%s |
158
|
|
|
|
|
|
|
$self->tag_left_in,$self->name,$self->tag_attr; |
159
|
0
|
|
|
|
|
|
my $end = sprintf qq|%s|,$self->tag_right_in; |
160
|
0
|
|
|
|
|
|
my $option; |
161
|
0
|
0
|
|
|
|
|
return unless ref $self->value eq 'ARRAY'; |
162
|
0
|
|
|
|
|
|
for my $val (@{$self->value}) { |
|
0
|
|
|
|
|
|
|
163
|
0
|
0
|
|
|
|
|
my $selected = $self->is_selected($val) ? 'selected': ''; |
164
|
0
|
|
|
|
|
|
$option .= sprintf qq||, |
165
|
|
|
|
|
|
|
$val,$self->tag_attr,$selected,$self->gen_tag_val_label($val); |
166
|
|
|
|
|
|
|
} |
167
|
0
|
|
|
|
|
|
return join "\n",($start,$option,$end,); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub _RadioCheckbox { |
171
|
0
|
|
|
0
|
|
|
my $self = shift; |
172
|
0
|
|
|
|
|
|
my $tag; |
173
|
0
|
0
|
|
|
|
|
return unless ref $self->value eq 'ARRAY'; |
174
|
0
|
|
|
|
|
|
for my $val (@{$self->value}) { |
|
0
|
|
|
|
|
|
|
175
|
0
|
0
|
|
|
|
|
my $checked = $self->is_checked($val) ? 'checked': ''; |
176
|
0
|
|
|
|
|
|
$tag .= sprintf |
177
|
|
|
|
|
|
|
qq|%s%s%s|,( |
178
|
|
|
|
|
|
|
$self->tag_left_in, |
179
|
|
|
|
|
|
|
$self->name,$self->type,$val,$self->tag_attr, |
180
|
|
|
|
|
|
|
$checked,$self->gen_tag_val_label($val), |
181
|
|
|
|
|
|
|
$self->tag_right_in, |
182
|
|
|
|
|
|
|
); |
183
|
|
|
|
|
|
|
} |
184
|
0
|
|
|
|
|
|
return $tag; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub _Textarea { |
188
|
0
|
|
|
0
|
|
|
my $self = shift; |
189
|
0
|
|
|
|
|
|
return sprintf qq|%s%s|,( |
190
|
|
|
|
|
|
|
$self->tag_left_in, |
191
|
|
|
|
|
|
|
$self->name,$self->tag_attr,$self->value, |
192
|
|
|
|
|
|
|
$self->tag_right_in, |
193
|
|
|
|
|
|
|
); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub gen_tag_val_label { |
197
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
198
|
0
|
|
|
|
|
|
my $key = shift; |
199
|
0
|
0
|
|
|
|
|
my $label = $self->tag_val_label ne '' ? $self->tag_val_label : {}; |
200
|
0
|
0
|
|
|
|
|
return defined $label->{$key} ? $label->{$key} : $key; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
1; |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
__END__ |