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