line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Tag::Regroup; |
2
|
2
|
|
|
2
|
|
805
|
use strict; use utf8; use warnings FATAL => 'all'; |
|
2
|
|
|
2
|
|
2
|
|
|
2
|
|
|
2
|
|
49
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
80
|
|
|
2
|
|
|
|
|
43
|
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
62
|
|
3
|
2
|
|
|
2
|
|
7
|
use parent 'DTL::Fast::Tag::Simple'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
13
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$DTL::Fast::TAG_HANDLERS{'regroup'} = __PACKAGE__; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
104
|
use DTL::Fast::Variable; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
740
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#@Override |
10
|
|
|
|
|
|
|
sub parse_parameters |
11
|
|
|
|
|
|
|
{ |
12
|
2
|
|
|
2
|
0
|
3
|
my $self = shift; |
13
|
|
|
|
|
|
|
|
14
|
2
|
50
|
|
|
|
17
|
if( $self->{'parameter'} =~ /^\s*(.+)\s+by\s+(.+?)\s+as\s+(.+?)\s*$/si ) |
15
|
|
|
|
|
|
|
{ |
16
|
2
|
|
|
|
|
7
|
@{$self}{qw( source grouper target_name)} = ( |
|
2
|
|
|
|
|
6
|
|
17
|
|
|
|
|
|
|
DTL::Fast::Variable->new($1) |
18
|
|
|
|
|
|
|
, [(split /\./, $2)] # do we need to backup strings here ? |
19
|
|
|
|
|
|
|
, $3 |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
2
|
50
|
|
|
|
6
|
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
|
|
|
|
|
4
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
#@Override |
33
|
|
|
|
|
|
|
sub render |
34
|
|
|
|
|
|
|
{ |
35
|
2
|
|
|
2
|
0
|
3
|
my ($self, $context) = @_; |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
6
|
my $source_array = $self->{'source'}->render($context); |
38
|
|
|
|
|
|
|
|
39
|
2
|
50
|
33
|
|
|
8
|
if( |
40
|
|
|
|
|
|
|
defined $source_array |
41
|
|
|
|
|
|
|
and ref $source_array eq 'ARRAY' |
42
|
|
|
|
|
|
|
) |
43
|
|
|
|
|
|
|
{ |
44
|
2
|
|
|
|
|
2
|
my @groupers = (); |
45
|
2
|
|
|
|
|
3
|
my $groups = {}; |
46
|
|
|
|
|
|
|
|
47
|
2
|
|
|
|
|
3
|
foreach my $source (@$source_array) |
48
|
|
|
|
|
|
|
{ |
49
|
10
|
50
|
33
|
|
|
32
|
if( |
50
|
|
|
|
|
|
|
defined $source |
51
|
|
|
|
|
|
|
and ref $source eq 'HASH' |
52
|
|
|
|
|
|
|
) |
53
|
|
|
|
|
|
|
{ |
54
|
10
|
|
|
|
|
20
|
my $grouper = $context->traverse($source, $self->{'grouper'}, $self); |
55
|
|
|
|
|
|
|
|
56
|
10
|
50
|
|
|
|
11
|
if( defined $grouper ) |
57
|
|
|
|
|
|
|
{ |
58
|
10
|
100
|
|
|
|
16
|
if( not exists $groups->{$grouper} ) |
59
|
|
|
|
|
|
|
{ |
60
|
6
|
|
|
|
|
4
|
push @groupers, $grouper; |
61
|
6
|
|
|
|
|
11
|
$groups->{$grouper} = []; |
62
|
|
|
|
|
|
|
} |
63
|
10
|
|
|
|
|
8
|
push @{$groups->{$grouper}}, $source; |
|
10
|
|
|
|
|
16
|
|
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
|
|
|
|
|
3
|
my $grouped = []; |
76
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
3
|
foreach my $grouper (@groupers) |
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
push @$grouped, { |
80
|
|
|
|
|
|
|
'grouper' => $grouper |
81
|
6
|
|
|
|
|
10
|
, 'list' => $groups->{$grouper} |
82
|
|
|
|
|
|
|
}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$context->set( |
87
|
2
|
|
|
|
|
6
|
$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
|
|
|
|
|
6
|
return ''; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |