blib/lib/DTL/Fast/Tag/Regroup.pm

filter: Statementstmt 91.3% 42 / 46 Branchbran 58.3% 7 / 12 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 72.5% 58 / 80 SCAR 26.2
CC
12
Cov
77%
render
13.1
parse_parameters
3.2
BEGIN
1.0
CRAP 13.7
« blib/lib/DTL/Fast/Tag/Ifchanged.pm ↑ Summary blib/lib/DTL/Fast/FilterManager.pm »
1 package DTL::Fast::Tag::Regroup;
2 2 ▶use strict; use utf8; use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use parent 'DTL::Fast::Tag::Simple';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 $DTL::Fast::TAG_HANDLERS{'regroup'} = __PACKAGE__;
6  
7 2 ▶use DTL::Fast::Variable;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 #@Override
10 sub parse_parameters
11 {
12 2 ▶ my $self = shift;
Subroutine parse_parameters: called CC=3 SCAR=11.6
Pod undocumented
13  
14 2 ▶ if( $self->{'parameter'} =~ /^\s*(.+)\s+by\s+(.+?)\s+as\s+(.+?)\s*$/si )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'parameter'} =~ /^\s*(.+)\s+by\s+(.+?)\s+as\s+(.+?)\s*$/is) { } 2 0 2
15 {
16 2 @{$self}{qw( source grouper target_name)} = (
17 DTL::Fast::Variable->new($1)
18 , [(split /\./, $2)] # do we need to backup strings here ?
19 , $3
20 );
21
22 2 ▶ die $self->get_parse_error("traget variable can't be traversable: $3") if $3 =~ /\./;
Branch: 1 branch
BranchTrueFalseTotal
if $3 =~ /\./ 0 2 2
23 }
24 else
25 {
26 0 die $self->get_parse_error("do not understand condition: $self->{'parameter'}");
27 }
28
29 2 return $self;
30 }
31  
32 #@Override
33 sub render
34 {
35 2 ▶ my ($self, $context) = @_;
Subroutine render: called CC=10 SCAR=25.8
Pod undocumented
36  
37 2 my $source_array = $self->{'source'}->render($context);
38
39 2 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (defined $source_array and ref $source_array eq 'ARRAY') { } 2 0 2
Condition33%1/3
defined $source_array and ref $source_array eq "ARRAY"
!ll&&!rl&&r
002
MC/DC0%0/2
defined $source_array and ref $source_array eq "ARRAY"
defined $source_array ref $source_array eq "ARRAY"
Truth table33%1/3
A and B
A= defined $source_arrayB= ref $source_array eq "ARRAY"
ABresult
0X0
100
111
40 defined $source_array
41 and ref $source_array eq 'ARRAY'
42 )
43 {
44 2 my @groupers = ();
45 2 my $groups = {};
46
47 2 foreach my $source (@$source_array)
48 {
49 10 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (defined $source and ref $source eq "HASH") 10 0 10
Condition33%1/3
defined $source and ref $source eq "HASH"
!ll&&!rl&&r
0010
MC/DC0%0/2
defined $source and ref $source eq "HASH"
defined $source ref $source eq "HASH"
Truth table33%1/3
A and B
A= defined $sourceB= ref $source eq "HASH"
ABresult
0X0
100
111
50 defined $source
51 and ref $source eq 'HASH'
52 )
53 {
54 10 my $grouper = $context->traverse($source, $self->{'grouper'}, $self);
55
56 10 ▶ if( defined $grouper )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grouper) { } 10 0 10
57 {
58 10 ▶ if( not exists $groups->{$grouper} )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $groups->{$grouper}) 6 4 10
59 {
60 6 push @groupers, $grouper;
61 6 $groups->{$grouper} = [];
62 }
63 10 push @{$groups->{$grouper}}, $source;
64 }
65 else
66 {
67 die $self->get_render_error(
68 $context,
69 0 "grouper value MUST exist and be defined in every source list item: ".join('.', @{$self->{'grouper'}})
70 );
71 }
72 }
73 }
74
75 2 my $grouped = [];
76
77 2 foreach my $grouper (@groupers)
78 {
79 push @$grouped, {
80 'grouper' => $grouper
81 6 , 'list' => $groups->{$grouper}
82 };
83 }
84
85
86 $context->set(
87 2 $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 ▶ , $self->{'source'}->{'original'} // 'undef'
Condition0%0/2
$self->{"source"}{"original"} // "undef"
l!l
00
MC/DC0%0/1
$self->{"source"}{"original"} // "undef"
$self->{"source"}{"original"}
Truth table0%0/2
A
A= $self->{"source"}{"original"}
Aresult
11
00
96 , ref $source_array
97 )
98 );
99 }
100
101 2 return '';
102 }
103  
104  
105 2 1;
« blib/lib/DTL/Fast/Tag/Ifchanged.pm ↑ Summary blib/lib/DTL/Fast/FilterManager.pm »