line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Filter::Add; |
2
|
2
|
|
|
2
|
|
834
|
use strict; use utf8; use warnings FATAL => 'all'; |
|
2
|
|
|
2
|
|
2
|
|
|
2
|
|
|
2
|
|
42
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
38
|
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
54
|
|
3
|
2
|
|
|
2
|
|
6
|
use parent 'DTL::Fast::Filter'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$DTL::Fast::FILTER_HANDLERS{'add'} = __PACKAGE__; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
124
|
use Scalar::Util qw(looks_like_number); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
709
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#@Override |
10
|
|
|
|
|
|
|
sub parse_parameters |
11
|
|
|
|
|
|
|
{ |
12
|
12
|
|
|
12
|
0
|
9
|
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
|
|
|
24
|
or not scalar @{$self->{'parameter'}} |
|
12
|
|
|
|
|
27
|
|
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
12
|
|
|
|
|
10
|
$self->{'parameters'} = [@{$self->{'parameter'}}]; |
|
12
|
|
|
|
|
15
|
|
21
|
|
|
|
|
|
|
|
22
|
12
|
|
|
|
|
22
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#@Override |
26
|
|
|
|
|
|
|
sub filter |
27
|
|
|
|
|
|
|
{ |
28
|
11
|
|
|
11
|
0
|
10
|
my ($self, $filter_manager, $value, $context) = @_; |
29
|
|
|
|
|
|
|
|
30
|
11
|
|
|
|
|
10
|
my $result = $value; |
31
|
11
|
|
|
|
|
9
|
my $value_type = ref $value; |
32
|
|
|
|
|
|
|
|
33
|
11
|
100
|
|
|
|
21
|
if( $value_type eq 'HASH' ) |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
34
|
|
|
|
|
|
|
{ |
35
|
1
|
|
|
|
|
3
|
$result = {%$value}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif( $value_type eq 'ARRAY' ) |
38
|
|
|
|
|
|
|
{ |
39
|
5
|
|
|
|
|
8
|
$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
|
|
|
|
|
9
|
foreach my $parameter (@{$self->{'parameters'}}) |
|
11
|
|
|
|
|
12
|
|
47
|
|
|
|
|
|
|
{ |
48
|
11
|
|
|
|
|
15
|
my $argument = $parameter->render($context); |
49
|
|
|
|
|
|
|
|
50
|
11
|
|
|
|
|
10
|
my $result_type = ref $result; |
51
|
11
|
|
|
|
|
10
|
my $argument_type = ref $argument; |
52
|
|
|
|
|
|
|
|
53
|
11
|
100
|
66
|
|
|
46
|
if( $result_type eq 'HASH' ) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
54
|
|
|
|
|
|
|
{ |
55
|
1
|
50
|
|
|
|
3
|
if( $argument_type eq 'ARRAY' ) |
|
|
0
|
|
|
|
|
|
56
|
|
|
|
|
|
|
{ |
57
|
1
|
|
|
|
|
13
|
%$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
|
|
|
|
8
|
if( $argument_type eq 'ARRAY' ) |
|
|
100
|
|
|
|
|
|
71
|
|
|
|
|
|
|
{ |
72
|
1
|
|
|
|
|
3
|
push @$result, @$argument; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
elsif( $argument_type eq 'HASH' ) |
75
|
|
|
|
|
|
|
{ |
76
|
1
|
|
|
|
|
4
|
push @$result, (%$argument); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else |
79
|
|
|
|
|
|
|
{ |
80
|
3
|
|
|
|
|
5
|
push @$result, $argument; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
elsif( looks_like_number($result) and looks_like_number($argument) ) |
84
|
|
|
|
|
|
|
{ |
85
|
1
|
|
|
|
|
2
|
$result += $argument; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else |
88
|
|
|
|
|
|
|
{ |
89
|
4
|
|
|
|
|
9
|
$result .= $argument; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
10
|
|
|
|
|
22
|
return $result; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |