line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::GroupedParams; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
866
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
464
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
11
|
1
|
|
|
1
|
1
|
667
|
my ( $self, $app, $conf ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
50
|
|
|
11
|
my $dms = $conf->{delimiters} || ['.']; |
14
|
1
|
|
|
|
|
3
|
my $dms_re = join( '|', map { quotemeta($_) } @$dms ); |
|
1
|
|
|
|
|
5
|
|
15
|
1
|
|
|
|
|
39
|
my $key_split_re = qr/^(.+?)(?:$dms_re)(.+)$/; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$app->helper( |
18
|
|
|
|
|
|
|
grouped_params => sub { |
19
|
2
|
|
|
2
|
|
144116
|
my ( $self, $group ) = @_; |
20
|
2
|
|
|
|
|
6
|
my $groups = {}; |
21
|
|
|
|
|
|
|
|
22
|
2
|
50
|
|
|
|
9
|
unless ( $self->stash('grouped_params') ) { |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
34
|
my $params = $self->req->params->to_hash; |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
1035
|
for my $key ( keys %$params ) { |
27
|
3
|
50
|
|
|
|
36
|
if ( my ($group, $name) = $key =~ $key_split_re ) { |
28
|
3
|
|
100
|
|
|
22
|
$groups->{$group} ||= {}; |
29
|
3
|
|
|
|
|
19
|
$groups->{$group}{$name} = $params->{$key}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else { |
35
|
0
|
|
|
|
|
0
|
$groups = $self->stash('grouped_params'); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
2
|
50
|
50
|
|
|
18
|
$group ? $groups->{$group} || {} : $groups; |
39
|
|
|
|
|
|
|
} |
40
|
1
|
|
|
|
|
12
|
); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |