line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Tag::Regroup; |
2
|
2
|
|
|
2
|
|
1239
|
use strict; use utf8; use warnings FATAL => 'all'; |
|
2
|
|
|
2
|
|
4
|
|
|
2
|
|
|
2
|
|
50
|
|
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
106
|
|
|
2
|
|
|
|
|
50
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
77
|
|
3
|
2
|
|
|
2
|
|
9
|
use parent 'DTL::Fast::Tag::Simple'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$DTL::Fast::TAG_HANDLERS{'regroup'} = __PACKAGE__; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
145
|
use DTL::Fast::Variable; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
1249
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#@Override |
10
|
|
|
|
|
|
|
sub parse_parameters |
11
|
|
|
|
|
|
|
{ |
12
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
13
|
|
|
|
|
|
|
|
14
|
2
|
50
|
|
|
|
25
|
if( $self->{'parameter'} =~ /^\s*(.+)\s+by\s+(.+?)\s+as\s+(.+?)\s*$/si ) |
15
|
|
|
|
|
|
|
{ |
16
|
2
|
|
|
|
|
11
|
@{$self}{qw( source grouper target_name)} = ( |
|
2
|
|
|
|
|
9
|
|
17
|
|
|
|
|
|
|
DTL::Fast::Variable->new($1) |
18
|
|
|
|
|
|
|
, [(split /\./, $2)] # do we need to backup strings here ? |
19
|
|
|
|
|
|
|
, $3 |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
2
|
50
|
|
|
|
8
|
die $self->get_parse_error("traget variable can't be traversable: $3") if $3 =~ /\./; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
else |
25
|
|
|
|
|
|
|
{ |
26
|
0
|
|
|
|
|
0
|
die $self->get_parse_error("do not understand condition: $self->{'parameter'}"); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
5
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
#@Override |
33
|
|
|
|
|
|
|
sub render |
34
|
|
|
|
|
|
|
{ |
35
|
2
|
|
|
2
|
0
|
3
|
my ($self, $context) = @_; |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
9
|
my $source_array = $self->{'source'}->render($context); |
38
|
|
|
|
|
|
|
|
39
|
2
|
50
|
33
|
|
|
12
|
if( |
40
|
|
|
|
|
|
|
defined $source_array |
41
|
|
|
|
|
|
|
and ref $source_array eq 'ARRAY' |
42
|
|
|
|
|
|
|
) |
43
|
|
|
|
|
|
|
{ |
44
|
2
|
|
|
|
|
3
|
my @groupers = (); |
45
|
2
|
|
|
|
|
4
|
my $groups = {}; |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
|
|
4
|
foreach my $source (@$source_array) |
48
|
|
|
|
|
|
|
{ |
49
|
10
|
50
|
33
|
|
|
51
|
if( |
50
|
|
|
|
|
|
|
defined $source |
51
|
|
|
|
|
|
|
and ref $source eq 'HASH' |
52
|
|
|
|
|
|
|
) |
53
|
|
|
|
|
|
|
{ |
54
|
10
|
|
|
|
|
34
|
my $grouper = $context->traverse($source, $self->{'grouper'}, $self); |
55
|
|
|
|
|
|
|
|
56
|
10
|
50
|
|
|
|
21
|
if( defined $grouper ) |
57
|
|
|
|
|
|
|
{ |
58
|
10
|
100
|
|
|
|
22
|
if( not exists $groups->{$grouper} ) |
59
|
|
|
|
|
|
|
{ |
60
|
6
|
|
|
|
|
9
|
push @groupers, $grouper; |
61
|
6
|
|
|
|
|
15
|
$groups->{$grouper} = []; |
62
|
|
|
|
|
|
|
} |
63
|
10
|
|
|
|
|
13
|
push @{$groups->{$grouper}}, $source; |
|
10
|
|
|
|
|
26
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else |
66
|
|
|
|
|
|
|
{ |
67
|
|
|
|
|
|
|
die $self->get_render_error( |
68
|
|
|
|
|
|
|
$context, |
69
|
0
|
|
|
|
|
0
|
"grouper value MUST exist and be defined in every source list item: ".join('.', @{$self->{'grouper'}}) |
|
0
|
|
|
|
|
0
|
|
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
11
|
my $grouped = []; |
76
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
4
|
foreach my $grouper (@groupers) |
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
push @$grouped, { |
80
|
|
|
|
|
|
|
'grouper' => $grouper |
81
|
6
|
|
|
|
|
23
|
, 'list' => $groups->{$grouper} |
82
|
|
|
|
|
|
|
}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$context->set( |
87
|
2
|
|
|
|
|
8
|
$self->{'target_name'} => $grouped |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else |
91
|
|
|
|
|
|
|
{ |
92
|
|
|
|
|
|
|
die $self->get_render_error( |
93
|
|
|
|
|
|
|
$context, |
94
|
|
|
|
|
|
|
sprintf( "regroup can be applied to lists only: %s is a %s" |
95
|
0
|
|
0
|
|
|
0
|
, $self->{'source'}->{'original'} // 'undef' |
96
|
|
|
|
|
|
|
, ref $source_array |
97
|
|
|
|
|
|
|
) |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
2
|
|
|
|
|
10
|
return ''; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |