line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Filter::Add; |
2
|
2
|
|
|
2
|
|
1293
|
use strict; use utf8; use warnings FATAL => 'all'; |
|
2
|
|
|
2
|
|
4
|
|
|
2
|
|
|
2
|
|
49
|
|
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
48
|
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
67
|
|
3
|
2
|
|
|
2
|
|
9
|
use parent 'DTL::Fast::Filter'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$DTL::Fast::FILTER_HANDLERS{'add'} = __PACKAGE__; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
136
|
use Scalar::Util qw(looks_like_number); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
910
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#@Override |
10
|
|
|
|
|
|
|
sub parse_parameters |
11
|
|
|
|
|
|
|
{ |
12
|
12
|
|
|
12
|
0
|
15
|
my $self = shift; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
die $self->get_parse_error("no single arguments passed to the add ".__PACKAGE__) |
15
|
|
|
|
|
|
|
if( |
16
|
|
|
|
|
|
|
ref $self->{'parameter'} ne 'ARRAY' |
17
|
12
|
50
|
33
|
|
|
35
|
or not scalar @{$self->{'parameter'}} |
|
12
|
|
|
|
|
45
|
|
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
12
|
|
|
|
|
14
|
$self->{'parameters'} = [@{$self->{'parameter'}}]; |
|
12
|
|
|
|
|
28
|
|
21
|
|
|
|
|
|
|
|
22
|
12
|
|
|
|
|
40
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#@Override |
26
|
|
|
|
|
|
|
sub filter |
27
|
|
|
|
|
|
|
{ |
28
|
11
|
|
|
11
|
0
|
21
|
my ($self, $filter_manager, $value, $context) = @_; |
29
|
|
|
|
|
|
|
|
30
|
11
|
|
|
|
|
13
|
my $result = $value; |
31
|
11
|
|
|
|
|
16
|
my $value_type = ref $value; |
32
|
|
|
|
|
|
|
|
33
|
11
|
100
|
|
|
|
35
|
if( $value_type eq 'HASH' ) |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
34
|
|
|
|
|
|
|
{ |
35
|
1
|
|
|
|
|
4
|
$result = {%$value}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif( $value_type eq 'ARRAY' ) |
38
|
|
|
|
|
|
|
{ |
39
|
5
|
|
|
|
|
13
|
$result = [@$value]; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif( $value_type ) # @todo here we can implement ->add interface |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
|
|
0
|
die $self->get_render_error("don't know how to add anything to $value_type"); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
11
|
|
|
|
|
13
|
foreach my $parameter (@{$self->{'parameters'}}) |
|
11
|
|
|
|
|
19
|
|
47
|
|
|
|
|
|
|
{ |
48
|
11
|
|
|
|
|
34
|
my $argument = $parameter->render($context); |
49
|
|
|
|
|
|
|
|
50
|
11
|
|
|
|
|
16
|
my $result_type = ref $result; |
51
|
11
|
|
|
|
|
19
|
my $argument_type = ref $argument; |
52
|
|
|
|
|
|
|
|
53
|
11
|
100
|
66
|
|
|
40
|
if( $result_type eq 'HASH' ) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
54
|
|
|
|
|
|
|
{ |
55
|
1
|
50
|
|
|
|
4
|
if( $argument_type eq 'ARRAY' ) |
|
|
0
|
|
|
|
|
|
56
|
|
|
|
|
|
|
{ |
57
|
1
|
|
|
|
|
16
|
%$result = (%$result, @$argument); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
elsif( $argument_type eq 'HASH' ) |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
|
|
0
|
%$result = (%$result, %$argument); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
|
|
0
|
die $self->get_render_error("it's not possible to add a single value to a hash"); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
elsif( $result_type eq 'ARRAY' ) |
69
|
|
|
|
|
|
|
{ |
70
|
5
|
100
|
|
|
|
18
|
if( $argument_type eq 'ARRAY' ) |
|
|
100
|
|
|
|
|
|
71
|
|
|
|
|
|
|
{ |
72
|
1
|
|
|
|
|
5
|
push @$result, @$argument; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
elsif( $argument_type eq 'HASH' ) |
75
|
|
|
|
|
|
|
{ |
76
|
1
|
|
|
|
|
5
|
push @$result, (%$argument); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else |
79
|
|
|
|
|
|
|
{ |
80
|
3
|
|
|
|
|
8
|
push @$result, $argument; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
elsif( looks_like_number($result) and looks_like_number($argument) ) |
84
|
|
|
|
|
|
|
{ |
85
|
1
|
|
|
|
|
3
|
$result += $argument; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else |
88
|
|
|
|
|
|
|
{ |
89
|
4
|
|
|
|
|
9
|
$result .= $argument; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
10
|
|
|
|
|
38
|
return $result; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |