Pure/Iterator.pm

filter: Statementstmt 43.7% 49 / 112 Branchbran 22.0% 11 / 50 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 21.8% 12 / 55 Podpod 0.0% 0 / 19 totaltotal 28.5% 72 / 252 CC 30 SCAR 25.5
CC
30
Cov
35%
from_object
90.0
from_hash
6.4
__ANON__
6.0
CRAP 12.8
↑ Summary Pure/ParseUtils.pm »
1 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Template::Pure::Iterator;
5  
6 ## Please not everything here is internal code... it will likely change a
7 ## lot so please rely only on the public interface.
8  
9 13 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub from_proto {
12 4 ▶ my ($class, $proto, $sort_cb, $filter_cb, $options) = @_;
Subroutine from_proto: called CC=2 SCAR=7.4
Pod undocumented
13 4 ▶ if(blessed $proto) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($proto)) { } 0 4 4
14 0 return $class->from_object($proto, $sort_cb, $filter_cb, $options);
15 } else {
16 4 my $type = 'from_' .lc ref $proto;
17 4 return $class->$type($proto, $sort_cb, $filter_cb, $options);
18 }
19 }
20  
21 sub from_object {
22 0 ▶ my ($class, $obj, $sort_cb, $filter_cb, $options) = @_;
Subroutine from_object: not called CC=9 SCAR=45.0
Pod undocumented
23 0 my ($index, $current) = (0);
24
25 0 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (my $next = $obj->can('next') and my $all = $obj->can('all') and my $reset = $obj->can('reset') and my $count = $obj->can('count')) { } 0 0 0
Condition0%0/9
my $next = $obj->can("next") and my $all = $obj->can("all") and my $reset = $obj->can("reset") and my $count = $obj->can("count")
!ll&&!rl&&r
000
my $next = $obj->can("next") and my $all = $obj->can("all") and my $reset = $obj->can("reset")
!ll&&!rl&&r
000
my $next = $obj->can("next") and my $all = $obj->can("all")
!ll&&!rl&&r
000
MC/DC0%0/4
my $next = $obj->can("next") and my $all = $obj->can("all") and my $reset = $obj->can("reset") and my $count = $obj->can("count")
my $next = $obj->can("next") my $all = $obj->can("all") my $reset = $obj->can("reset") my $count = $obj->can("count")
Truth table0%0/5
A and B and C and D
A= my $next = $obj->can("next")B= my $all = $obj->can("all")C= my $reset = $obj->can("reset")D= my $count = $obj->can("count")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
26 (my $next = $obj->can('next')) &&
27 (my $all = $obj->can('all')) &&
28 (my $reset = $obj->can('reset')) &&
29 (my $count = $obj->can('count'))
30 ) {
31  
32 0 ▶ $obj = $filter_cb->($obj) if defined $filter_cb;
Branch: 1 branch
BranchTrueFalseTotal
if defined $filter_cb 0 0 0
33 0 ▶ $obj = $sort_cb->($obj) if defined $sort_cb;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sort_cb 0 0 0
34  
35 return bless +{
36 0 ▶ _index => sub { return $index },
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 0 ▶ _current_value => sub { return $current },
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 0 ▶ _max_index => sub { return $count->() - 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 0 ▶ _count => sub { return $count->() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 _next => sub {
41 0 ▶ if(my $next = $next->()) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if (my $next = &$next()) { } 0 0 0
42 0 $current = $next;
43 0 $index++;
44 0 return $next;
45 } else {
46 0 return undef;
47 }
48 },
49 0 ▶ _reset => sub { $reset->() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 ▶ _all => sub { return $all->() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 0 ▶ _is_first => sub { return (($index - 1) == 0 ? 1:0) },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$index - 1 == 0 ? : 0 0 0
52 0 ▶ _is_last => sub { return $index == $count->() ? 1:0 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$index == &$count() ? : 0 0 0
53 0 ▶ _is_even => sub { return $index % 2 ? 0:1 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$index % 2 ? : 0 0 0
54 0 ▶ _is_odd => sub { return $index % 2 ? 1:0 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$index % 2 ? : 0 0 0
55 0 }, $class;
56 } else {
57 0 my %hash;
58 0 ▶ if(my $fields = $obj->can($options->{fields_method} ||'display_fields')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fields = $obj->can($options->{'fields_method'} || 'display_fields')) { } 0 0 0
Condition0%0/2
$options->{'fields_method'} || 'display_fields'
l!l
00
MC/DC0%0/1
$options->{'fields_method'} || 'display_fields'
$options->{'fields_method'}
Truth table0%0/2
A
A= $options->{'fields_method'}
Aresult
11
00
59 0 %hash = map { $_ => $obj->$_ } ($fields->());
60 } else {
61 0 %hash = %{$obj};
62 }
63  
64 0 return $class->from_hash(\%hash, $sort_cb, $filter_cb);
65 }
66  
67 }
68  
69 sub from_hash {
70 1 ▶ my ($class, $hashref, $sort_cb, $filter_cb) = @_;
Subroutine from_hash: called CC=4 SCAR=18.6
Pod undocumented
71 1 ▶ my @keys = defined $filter_cb ? grep { $filter_cb->($_, $hashref->{$_}) ? $_ : undef } keys %$hashref : keys %$hashref;
Branch: 2 branches
BranchTrueFalseTotal
defined $filter_cb ? : 0 1 1
&$filter_cb($_, $hashref->{$_}) ? : 0 0 0
72  
73 1 ▶ if(defined $sort_cb) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sort_cb) 1 0 1
74 1 @keys = sort { $sort_cb->($hashref, $a, $b) } @keys;
75 }
76  
77 1 my $index = 0;
78 1 my $current;
79 1 my $current_key = $hashref->{$keys[0]};
80 return bless +{
81 3 ▶ _index => sub { return $current_key },
Subroutine __ANON__: called CC=1 SCAR=0.0
82 0 ▶ _current_value => sub { return $current },
Subroutine __ANON__: not called CC=1 SCAR=6.9
83 0 ▶ _max_index => sub { return undef; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 0 ▶ _count => sub { return scalar @keys },
Subroutine __ANON__: not called CC=1 SCAR=6.9
85 _next => sub {
86 4 ▶ return undef if $index > $#keys;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $index > $#keys 1 3 4
87 3 $current_key = $keys[$index];
88 3 my $value = $hashref->{$current_key};
89 3 $index++;
90 3 $current = $value;
91 3 return $value;
92 },
93 0 ▶ _reset => sub { $index = 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
94 0 ▶ _all => sub { return %{$hashref} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 0 ▶ _is_first => sub { return $index-1 == 0 ? 1:0 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$index - 1 == 0 ? : 0 0 0
96 0 ▶ _is_last => sub { return $index-1 == $#keys ? 1:0 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$index - 1 == $#keys ? : 0 0 0
97 0 ▶ _is_even => sub { return $index % 2 ? 0:1 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$index % 2 ? : 0 0 0
98 0 ▶ _is_odd => sub { return $index % 2 ? 1:0 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$index % 2 ? : 0 0 0
99 1 }, $class;
100 }
101  
102 sub from_array {
103 3 ▶ my ($class, $arrayref, $sort_cb, $filter_cb) = @_;
Subroutine from_array: called CC=3 SCAR=13.4
Pod undocumented
104 3 ▶ my @array = defined $filter_cb ? grep { $filter_cb->($_) } @$arrayref : @$arrayref;
Branch: 1 branch
BranchTrueFalseTotal
defined $filter_cb ? : 1 2 3
105  
106 3 ▶ if(defined $sort_cb) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sort_cb) 1 2 3
107 1 @array = sort { $sort_cb->($arrayref, $a, $b) } @array;
108 }
109  
110 3 my $index = 0;
111 3 my $current;
112 return bless +{
113 5 ▶ _index => sub { return $index },
Subroutine __ANON__: called CC=1 SCAR=0.0
114 0 ▶ _current_value => sub { return $current },
Subroutine __ANON__: not called CC=1 SCAR=6.9
115 0 ▶ _max_index => sub { return $#array },
Subroutine __ANON__: not called CC=1 SCAR=6.9
116 0 ▶ _count => sub { return scalar @array },
Subroutine __ANON__: not called CC=1 SCAR=6.9
117 _next => sub {
118 11 ▶ return undef if $index > $#array;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $index > $#array 3 8 11
119 8 my $value = $array[$index];
120 8 $index++;
121 8 $current = $value;
122 8 return $value;
123 },
124 0 ▶ _reset => sub { $index = 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
125 0 ▶ _all => sub { return @array },
Subroutine __ANON__: not called CC=1 SCAR=6.9
126 0 ▶ _is_first => sub { return $index-1 == 0 ? 1:0 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$index - 1 == 0 ? : 0 0 0
127 0 ▶ _is_last => sub { return $index-1 == $#array ? 1:0 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$index - 1 == $#array ? : 0 0 0
128 0 ▶ _is_even => sub { return $index % 2 ? 0:1 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$index % 2 ? : 0 0 0
129 0 ▶ _is_odd => sub { return $index % 2 ? 1:0 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$index % 2 ? : 0 0 0
130 3 }, $class;
131 }
132  
133 sub current_value {
134 0 ▶ my ($self) = @_;
Subroutine current_value: not called CC=1 SCAR=6.9
Pod undocumented
135 0 return $self->{_current_value}->($self);
136 }
137  
138 sub next {
139 15 ▶ my ($self) = @_;
Subroutine next: called CC=1 SCAR=0.0
Pod undocumented
140 15 return $self->{_next}->($self);
141 }
142  
143 sub reset {
144 0 ▶ my ($self) = @_;
Subroutine reset: not called CC=1 SCAR=6.9
Pod undocumented
145 0 return $self->{_reset}->($self);
146 }
147  
148 sub all {
149 0 ▶ my ($self) = @_;
Subroutine all: not called CC=1 SCAR=6.9
Pod undocumented
150 0 return $self->{_all}->($self);
151 }
152  
153 sub count {
154 0 ▶ my ($self) = @_;
Subroutine count: not called CC=1 SCAR=6.9
Pod undocumented
155 0 return $self->{_count}->($self);
156 }
157  
158 sub index {
159 8 ▶ my ($self) = @_;
Subroutine index: called CC=1 SCAR=0.0
Pod undocumented
160 8 return $self->{_index}->($self);
161 }
162  
163 sub max_index {
164 0 ▶ my ($self) = @_;
Subroutine max_index: not called CC=1 SCAR=6.9
Pod undocumented
165 0 return $self->{_max_index}->($self);
166 }
167  
168 0 ▶sub is_first { $_[0]->{_is_first}->($_[0]) }
Subroutine is_first: not called CC=1 SCAR=6.9
Pod undocumented
169 0 ▶sub is_last { $_[0]->{_is_last}->($_[0]) }
Subroutine is_last: not called CC=1 SCAR=6.9
Pod undocumented
170 0 ▶sub is_even { $_[0]->{_is_even}->($_[0]) }
Subroutine is_even: not called CC=1 SCAR=6.9
Pod undocumented
171 0 ▶sub is_odd { $_[0]->{_is_odd}->($_[0]) }
Subroutine is_odd: not called CC=1 SCAR=6.9
Pod undocumented
172  
173 ▶sub is_paged { }
Subroutine is_paged: not called CC=1 SCAR=0.0
Pod undocumented
174  
175 ▶sub pager { }
Subroutine pager: not called CC=1 SCAR=0.0
Pod undocumented
176  
177 ▶sub page { }
Subroutine page: not called CC=1 SCAR=0.0
Pod undocumented
178  
179 ▶sub is_ordered { }
Subroutine is_ordered: not called CC=1 SCAR=0.0
Pod undocumented
180  
181 13 1;
↑ Summary Pure/ParseUtils.pm »