line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormStructure; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
49664
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
86
|
|
4
|
2
|
|
|
2
|
|
12
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
126
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.04'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
1702
|
use HTML::FormStructure::Query; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
17
|
|
8
|
2
|
|
|
2
|
|
1345
|
use HTML::FormStructure::Validation; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
156
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
10
|
use base qw(Class::Accessor); |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
3822
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _my_accessors { |
13
|
1
|
|
|
1
|
|
4
|
qw(action method enctype r validator); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _init { |
17
|
1
|
|
|
1
|
|
2
|
my $opt = shift; |
18
|
1
|
50
|
|
|
|
6
|
$opt->{form_accessors} = defined $opt->{form_accessors} ? |
19
|
|
|
|
|
|
|
$opt->{form_accessors} : []; |
20
|
1
|
|
|
|
|
16
|
__PACKAGE__->mk_accessors( |
21
|
1
|
|
|
|
|
4
|
&_my_accessors,@{$opt->{form_accessors}} |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
26
|
1
|
|
|
1
|
1
|
5569
|
my($class, $form, $r, $opt) = @_; |
27
|
1
|
|
|
|
|
6
|
_init($opt); |
28
|
1
|
|
|
|
|
325
|
my @query; |
29
|
1
|
|
|
|
|
2
|
for my $query (@{$form}) { |
|
1
|
|
|
|
|
3
|
|
30
|
7
|
100
|
|
|
|
21
|
if (ref $query->{consist} eq 'ARRAY') { |
31
|
1
|
|
|
|
|
3
|
my @tmp_query; |
32
|
1
|
|
|
|
|
2
|
for my $q (@{$query->{consist}}) { |
|
1
|
|
|
|
|
3
|
|
33
|
3
|
|
|
|
|
11
|
my $tmp_q = HTML::FormStructure::Query->new($q,$opt); |
34
|
3
|
|
|
|
|
7
|
push @tmp_query, $tmp_q; |
35
|
|
|
|
|
|
|
} |
36
|
1
|
|
|
|
|
4
|
$query->{consist} = \@tmp_query; |
37
|
1
|
|
|
|
|
4
|
push @query, HTML::FormStructure::Query->new($query,$opt); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
6
|
|
|
|
|
25
|
push @query, HTML::FormStructure::Query->new($query,$opt); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
1
|
|
|
|
|
5
|
my $self = bless { _form_data => \@query }, $class; |
44
|
1
|
50
|
|
|
|
7
|
$self->r($r) if defined $r; |
45
|
1
|
|
|
|
|
20
|
return $self; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub list_as_array { |
49
|
17
|
|
|
17
|
1
|
31
|
return @{shift->{_form_data}}; |
|
17
|
|
|
|
|
45
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub list_as_arrayref { |
53
|
1
|
|
|
1
|
1
|
11
|
return shift->{_form_data}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub have { |
57
|
12
|
|
|
12
|
1
|
29
|
my $self = shift; |
58
|
12
|
|
|
|
|
20
|
my $meth = shift; |
59
|
12
|
|
|
|
|
11
|
my @wanted; |
60
|
12
|
|
|
|
|
23
|
for my $query ($self->list_as_array) { |
61
|
84
|
100
|
|
|
|
749
|
if ($query->$meth()) { |
62
|
27
|
50
|
|
|
|
257
|
push @wanted, $query if defined $query->$meth(); |
63
|
|
|
|
|
|
|
} |
64
|
84
|
100
|
|
|
|
763
|
next unless ($query->consist); |
65
|
12
|
|
|
|
|
186
|
for my $q ($query->array_of('consist')) { |
66
|
36
|
100
|
|
|
|
250
|
next unless $q->$meth(); |
67
|
18
|
50
|
|
|
|
167
|
push @wanted, $q if defined $q->$meth(); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
12
|
|
|
|
|
156
|
return @wanted; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _do_search { |
74
|
3
|
|
|
3
|
|
5
|
my $self = shift; |
75
|
3
|
|
|
|
|
4
|
my $key = shift; |
76
|
3
|
|
|
|
|
4
|
my $val = shift; |
77
|
3
|
|
|
|
|
4
|
my $type = shift; |
78
|
3
|
|
|
|
|
4
|
my @ret; |
79
|
3
|
|
|
|
|
7
|
for my $query ($self->list_as_array) { |
80
|
21
|
50
|
33
|
|
|
235
|
if (defined $type && $type eq 'like') { |
81
|
0
|
0
|
|
|
|
0
|
push @ret,$query if $query->$key() =~ /$val/; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
21
|
100
|
|
|
|
61
|
push @ret,$query if $query->$key() eq $val; |
85
|
|
|
|
|
|
|
} |
86
|
21
|
|
|
|
|
223
|
for my $q ($query->array_of('consist')) { |
87
|
9
|
50
|
|
|
|
71
|
push @ret, $q if $q->$key() eq $val; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
3
|
|
|
|
|
38
|
return @ret; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
3
|
|
|
3
|
1
|
11
|
sub search { shift->_do_search(@_)} |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
0
|
1
|
0
|
sub search_like { shift->_do_search(@_,'like')} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub fetch { |
98
|
2
|
|
|
2
|
1
|
44
|
my $self = shift; |
99
|
2
|
|
|
|
|
6
|
my $target = ($self->search('name',shift))[0]; |
100
|
2
|
50
|
|
|
|
12
|
return $target ? $target : ''; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub group { |
104
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
105
|
0
|
|
|
|
|
0
|
my $key = shift; |
106
|
0
|
|
|
|
|
0
|
my $ret = {}; |
107
|
0
|
|
|
|
|
0
|
for my $query ($self->have($key)) { |
108
|
0
|
|
|
|
|
0
|
push @{$ret->{$query->$key()}}, $query; |
|
0
|
|
|
|
|
0
|
|
109
|
|
|
|
|
|
|
} |
110
|
0
|
|
|
|
|
0
|
return map { $ret->{$_}} keys %{$ret}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub param { |
114
|
1
|
|
|
1
|
1
|
46
|
my $self = shift; |
115
|
1
|
|
|
|
|
5
|
my $target = ($self->search('name',shift))[0]; |
116
|
1
|
50
|
|
|
|
7
|
return $target ? $target->store : ''; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub store_request { |
120
|
1
|
|
|
1
|
1
|
76
|
my $self = shift; |
121
|
1
|
|
|
|
|
3
|
for my $query ($self->list_as_array) { |
122
|
7
|
50
|
|
|
|
83
|
if (defined $query->storef) { |
123
|
0
|
|
|
|
|
0
|
$query->store( |
124
|
|
|
|
|
|
|
sprintf $query->storef, |
125
|
|
|
|
|
|
|
$self->r->param($query->name) |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
else { |
129
|
7
|
|
|
|
|
66
|
$query->store($self->r->param($query->name)); |
130
|
|
|
|
|
|
|
} |
131
|
7
|
|
|
|
|
284
|
for my $q ($query->array_of('consist')) { |
132
|
3
|
|
|
|
|
85
|
$q->store($self->r->param($q->name)); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub hashref { |
138
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
139
|
0
|
|
|
|
|
0
|
my ($key,$val,$situation) = @_; |
140
|
0
|
|
|
|
|
0
|
my $hashref = {}; |
141
|
0
|
|
|
|
|
0
|
for ($self->have($key)) { |
142
|
0
|
0
|
|
|
|
0
|
if ($situation) { |
143
|
0
|
0
|
|
|
|
0
|
next unless defined $_->$situation(); |
144
|
|
|
|
|
|
|
} |
145
|
0
|
0
|
|
|
|
0
|
$hashref->{$_->name} = $_->$val() if defined $_->$val(); |
146
|
|
|
|
|
|
|
} |
147
|
0
|
|
|
|
|
0
|
return $hashref; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
1
|
|
|
1
|
0
|
4
|
sub query_combine { shift->consist_query } |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub consist_query { |
153
|
2
|
|
|
2
|
1
|
42
|
my $self = shift; |
154
|
2
|
|
|
|
|
5
|
for my $query ($self->have('consist')) { |
155
|
2
|
|
|
|
|
5
|
my $value; |
156
|
2
|
50
|
|
|
|
6
|
if (defined $query->consistf) { |
157
|
2
|
|
|
|
|
20
|
$value = sprintf $query->consistf, |
158
|
|
|
|
|
|
|
map $self->r->param($_->name),$query->array_of('consist'); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
else { |
161
|
0
|
|
|
|
|
0
|
for my $q ($query->array_of('consist')) { |
162
|
0
|
0
|
|
|
|
0
|
$value .= defined $self->r->param($q->name) ? |
163
|
|
|
|
|
|
|
$self->r->param($q->name) : ''; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
2
|
50
|
|
|
|
212
|
$self->r->param($query->name => $value) if defined $value; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
__END__ |