line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package # hide from Pause |
2
|
|
|
|
|
|
|
HTML::FormHandler::Params; |
3
|
|
|
|
|
|
|
# ABSTRACT: params handling |
4
|
|
|
|
|
|
|
|
5
|
140
|
|
|
140
|
|
292467
|
use Moose; |
|
140
|
|
|
|
|
251
|
|
|
140
|
|
|
|
|
991
|
|
6
|
140
|
|
|
140
|
|
635334
|
use Carp; |
|
140
|
|
|
|
|
253
|
|
|
140
|
|
|
|
|
101438
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'separator' => ( isa => 'Str', is => 'rw', default => '.' ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub split_name { |
11
|
582
|
|
|
582
|
0
|
673
|
my ( $self, $name, $sep ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
582
|
|
33
|
|
|
962
|
$sep ||= $self->separator; |
14
|
582
|
|
|
|
|
710
|
$sep = "\Q$sep"; |
15
|
|
|
|
|
|
|
|
16
|
582
|
50
|
|
|
|
1036
|
if ( $sep eq '[]' ) { |
17
|
0
|
|
|
|
|
0
|
return grep { defined } ( |
|
0
|
|
|
|
|
0
|
|
18
|
|
|
|
|
|
|
$name =~ / |
19
|
|
|
|
|
|
|
^ (\w+) # root param |
20
|
|
|
|
|
|
|
| \[ (\w+) \] # nested |
21
|
|
|
|
|
|
|
/gx |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# These next two regexes are the escaping aware equivalent |
26
|
|
|
|
|
|
|
# to the following: |
27
|
|
|
|
|
|
|
# my ($first, @segments) = split(/\./, $name, -1); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# m// splits on unescaped '.' chars. Can't fail b/c \G on next |
30
|
|
|
|
|
|
|
# non ./ * -> escaped anything -> non ./ * |
31
|
582
|
|
|
|
|
5770
|
$name =~ m/^ ( [^\\$sep]* (?: \\(?:.|$) [^\\$sep]* )* ) /gx; |
32
|
582
|
|
|
|
|
842
|
my $first = $1; |
33
|
582
|
|
|
|
|
729
|
$first =~ s/\\(.)/$1/g; # remove escaping |
34
|
|
|
|
|
|
|
|
35
|
582
|
|
|
|
|
3391
|
my (@segments) = $name =~ |
36
|
|
|
|
|
|
|
# . -> ( non ./ * -> escaped anything -> non ./ * ) |
37
|
|
|
|
|
|
|
m/\G (?:[$sep]) ( [^\\$sep]* (?: \\(?:.|$) [^\\$sep]* )* ) /gx; |
38
|
|
|
|
|
|
|
# Escapes removed later, can be used to avoid using as array index |
39
|
|
|
|
|
|
|
|
40
|
582
|
|
|
|
|
1421
|
return ( $first, @segments ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub expand_hash { |
44
|
355
|
|
|
355
|
0
|
573
|
my ( $self, $flat, $sep ) = @_; |
45
|
|
|
|
|
|
|
|
46
|
355
|
|
|
|
|
476
|
my $deep = {}; |
47
|
355
|
|
33
|
|
|
10000
|
$sep ||= $self->separator; |
48
|
|
|
|
|
|
|
|
49
|
355
|
|
|
|
|
1086
|
for my $name ( keys %$flat ) { |
50
|
|
|
|
|
|
|
|
51
|
582
|
|
|
|
|
1438
|
my ( $first, @segments ) = $self->split_name( $name, $sep ); |
52
|
|
|
|
|
|
|
|
53
|
582
|
|
|
|
|
948
|
my $box_ref = \$deep->{$first}; |
54
|
582
|
|
|
|
|
811
|
for (@segments) { |
55
|
337
|
100
|
|
|
|
748
|
if ( /^(0|[1-9]\d*)$/ ) { |
56
|
118
|
100
|
|
|
|
200
|
$$box_ref = [] unless defined $$box_ref; |
57
|
118
|
50
|
|
|
|
200
|
croak "HFH: param clash for $name=$_" |
58
|
|
|
|
|
|
|
unless ref $$box_ref eq 'ARRAY'; |
59
|
118
|
|
|
|
|
236
|
$box_ref = \( $$box_ref->[$1] ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
219
|
50
|
|
|
|
413
|
s/\\(.)/$1/g if $sep; # remove escaping |
63
|
219
|
100
|
|
|
|
416
|
$$box_ref = {} unless defined $$box_ref; |
64
|
219
|
50
|
|
|
|
378
|
$$box_ref = { '' => $$box_ref } if ( !ref $$box_ref ); |
65
|
219
|
50
|
|
|
|
380
|
croak "HFH: param clash for $name=$_" |
66
|
|
|
|
|
|
|
unless ref $$box_ref eq 'HASH'; |
67
|
219
|
|
|
|
|
385
|
$box_ref = \( $$box_ref->{$_} ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
582
|
100
|
|
|
|
1025
|
if ( defined $$box_ref ) { |
71
|
2
|
50
|
|
|
|
6
|
croak "HFH: param clash for $name value $flat->{$name}" |
72
|
|
|
|
|
|
|
if ref $$box_ref ne 'HASH'; |
73
|
2
|
|
|
|
|
6
|
$box_ref = \( $$box_ref->{''} ); |
74
|
|
|
|
|
|
|
} |
75
|
582
|
|
|
|
|
916
|
$$box_ref = $flat->{$name}; |
76
|
|
|
|
|
|
|
} |
77
|
355
|
|
|
|
|
808
|
return $deep; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub collapse_hash { |
81
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
82
|
0
|
|
|
|
|
|
my $deep = shift; |
83
|
0
|
|
|
|
|
|
my $flat = {}; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$self->_collapse_hash( $deep, $flat, () ); |
86
|
0
|
|
|
|
|
|
return $flat; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub join_name { |
90
|
0
|
|
|
0
|
0
|
|
my ( $self, @array ) = @_; |
91
|
0
|
|
|
|
|
|
my $sep = substr( $self->separator, 0, 1 ); |
92
|
0
|
|
|
|
|
|
return join $sep, @array; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _collapse_hash { |
96
|
0
|
|
|
0
|
|
|
my ( $self, $deep, $flat, @segments ) = @_; |
97
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
if ( !ref $deep ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $name = $self->join_name(@segments); |
100
|
0
|
|
|
|
|
|
$flat->{$name} = $deep; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
elsif ( ref $deep eq 'HASH' ) { |
103
|
0
|
|
|
|
|
|
for ( keys %$deep ) { |
104
|
|
|
|
|
|
|
# escape \ and separator chars (once only, at this level) |
105
|
0
|
|
|
|
|
|
my $name = $_; |
106
|
0
|
0
|
|
|
|
|
if ( defined( my $sep = $self->separator ) ) { |
107
|
0
|
|
|
|
|
|
$sep = "\Q$sep"; |
108
|
0
|
|
|
|
|
|
$name =~ s/([\\$sep])/\\$1/g; |
109
|
|
|
|
|
|
|
} |
110
|
0
|
|
|
|
|
|
$self->_collapse_hash( $deep->{$_}, $flat, @segments, $name ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
elsif ( ref $deep eq 'ARRAY' ) { |
114
|
0
|
|
|
|
|
|
for ( 0 .. $#$deep ) { |
115
|
0
|
0
|
|
|
|
|
$self->_collapse_hash( $deep->[$_], $flat, @segments, $_ ) |
116
|
|
|
|
|
|
|
if defined $deep->[$_]; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
else { |
120
|
0
|
|
|
|
|
|
croak "Unknown reference type for ", $self->join_name(@segments), ":", ref $deep; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
125
|
140
|
|
|
140
|
|
837
|
use namespace::autoclean; |
|
140
|
|
|
|
|
235
|
|
|
140
|
|
|
|
|
1467
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=pod |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=encoding UTF-8 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 NAME |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
HTML::FormHandler::Params - params handling |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 VERSION |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
version 0.40067 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
FormHandler Contributors - see HTML::FormHandler |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Gerda Shank. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
151
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |