DOM58/_Collection.pm

filter: Statementstmt 91.6% 120 / 131 Branchbran 87.5% 35 / 40 Conditioncond 86.6% 13 / 15 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 97.3% 37 / 38 Podpod 0.0% 0 / 22 totaltotal 82.6% 210 / 254 CC 28 SCAR 9.0
CC
28
Cov
90%
_reduce
7.8
with_roles
4.1
uniq
4.0
CRAP 2.5
« DOM58.pm ↑ Summary
1 package Mojo::DOM58::_Collection;
2  
3 # This file is part of Mojo::DOM58 which is released under:
4 # The Artistic License 2.0 (GPL Compatible)
5 # See the documentation for Mojo::DOM58 for full license details.
6  
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use re ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use constant REDUCE => ($] >= 5.008009 ? \&List::Util::reduce : \&_reduce);
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$] >= 5.008009 ? : 3 0 3
15 3 ▶use constant HAS_IS_REGEXP => !!($] >= 5.010000);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # Role support requires Role::Tiny 2.000001+
18 3 ▶use constant ROLES =>
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 !!(eval { require Role::Tiny; Role::Tiny->VERSION('2.000001'); 1 });
20  
21 3 our $VERSION = '3.003';
22  
23 798 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
24 798 my $class = shift;
25 798 ▶ return bless [@_], ref $class || $class;
Condition66%2/3
ref $class || $class
l!l&&r!l&&!r
1526460
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
26 }
27  
28 1 ▶sub TO_JSON { [@{shift()}] }
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod undocumented
29  
30 3 ▶sub compact {
Subroutine compact: called CC=3 SCAR=11.0
Pod undocumented
31 3 my $self = shift;
32 3 ▶ return $self->new(grep { defined && (ref || length) } @$self);
Condition83%5/6
defined $_ && (ref $_ || length $_)
!ll&&!rl&&r
117
ref $_ or length $_
l!l&&r!l&&!r
071
MC/DC66%2/3
defined $_ && (ref $_ || length $_)
defined $_ ref $_ length $_
Truth table75%3/4
A && B or C
A= defined $_B= ref $_C= length $_
ABCresult
0XX0
1000
11X1
1011
33 }
34  
35 122 ▶sub each {
Subroutine each: called CC=3 SCAR=11.0
Pod undocumented
36 122 my ($self, $cb) = @_;
37 122 ▶ return @$self unless $cb;
Branch: 1 branch
BranchTrueFalseTotal
unless $cb 10 112 122
38 112 my $i = 1;
39 112 $_->$cb($i++) for @$self;
40 112 return $self;
41 }
42  
43 81 ▶sub first {
Subroutine first: called CC=3 SCAR=11.0
Pod undocumented
44 81 my ($self, $cb) = (shift, shift);
45 81 ▶ return $self->[0] unless $cb;
Branch: 1 branch
BranchTrueFalseTotal
unless $cb 70 11 81
46 11 ▶ return List::Util::first { $_ =~ $cb } @$self if HAS_IS_REGEXP ? re::is_regexp($cb) : ref $cb eq 'Regexp';
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &re::is_regexp($cb) 1 10 11
47 10 ▶ return List::Util::first { $_->$cb(@_) } @$self;
Subroutine __ANON__: called CC=1 SCAR=0.0
48 }
49  
50 5 ▶sub flatten { $_[0]->new(_flatten(@{$_[0]})) }
Subroutine flatten: called CC=1 SCAR=0.0
Pod undocumented
51  
52 35 ▶sub grep {
Subroutine grep: called CC=2 SCAR=6.9
Pod undocumented
53 35 my ($self, $cb) = (shift, shift);
54 35 ▶ return $self->new(grep { $_ =~ $cb } @$self) if HAS_IS_REGEXP ? re::is_regexp($cb) : ref $cb eq 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
if &re::is_regexp($cb) 1 34 35
55 34 return $self->new(grep { $_->$cb(@_) } @$self);
56 }
57  
58 9 ▶sub head {
Subroutine head: called CC=3 SCAR=11.0
Pod undocumented
59 9 my ($self, $size) = @_;
60 9 ▶ return $self->new(@$self) if $size > @$self;
Branch: 1 branch
BranchTrueFalseTotal
if $size > @$self 1 8 9
61 8 ▶ return $self->new(@$self[0 .. ($size - 1)]) if $size >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $size >= 0 4 4 8
62 4 return $self->new(@$self[0 .. ($#$self + $size)]);
63 }
64  
65 49 ▶sub join {
Subroutine join: called CC=2 SCAR=6.9
Pod undocumented
66 49 ▶ join +(defined($_[1]) ? $_[1] : ''), map {"$_"} @{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 46 3 49
67 }
68  
69 24 ▶sub last { shift->[-1] }
Subroutine last: called CC=1 SCAR=0.0
Pod undocumented
70  
71 60 ▶sub map {
Subroutine map: called CC=1 SCAR=0.0
Pod undocumented
72 60 my ($self, $cb) = (shift, shift);
73 60 return $self->new(map { $_->$cb(@_) } @$self);
74 }
75  
76 3 ▶sub reduce {
Subroutine reduce: called CC=1 SCAR=0.0
Pod undocumented
77 3 my $self = shift;
78 3 @_ = (@_, @$self);
79 3 goto &{REDUCE()};
80 }
81  
82 8 ▶sub reverse { $_[0]->new(reverse @{$_[0]}) }
Subroutine reverse: called CC=1 SCAR=0.0
Pod undocumented
83  
84 2 ▶sub shuffle { $_[0]->new(List::Util::shuffle @{$_[0]}) }
Subroutine shuffle: called CC=1 SCAR=0.0
Pod undocumented
85  
86 60 ▶sub size { scalar @{$_[0]} }
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
87  
88 8 ▶sub slice {
Subroutine slice: called CC=1 SCAR=0.0
Pod undocumented
89 8 my $self = shift;
90 8 return $self->new(@$self[@_]);
91 }
92  
93 6 ▶sub sort {
Subroutine sort: called CC=2 SCAR=6.9
Pod undocumented
94 6 my ($self, $cb) = @_;
95  
96 6 ▶ return $self->new(sort @$self) unless $cb;
Branch: 1 branch
BranchTrueFalseTotal
unless $cb 2 4 6
97  
98 4 my $caller = caller;
99 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
100 my @sorted = sort {
101 4 local (*{"${caller}::a"}, *{"${caller}::b"}) = (\$a, \$b);
102 12 $a->$cb($b);
103 } @$self;
104 4 return $self->new(@sorted);
105 }
106  
107 9 ▶sub tail {
Subroutine tail: called CC=3 SCAR=11.0
Pod undocumented
108 9 my ($self, $size) = @_;
109 9 ▶ return $self->new(@$self) if $size > @$self;
Branch: 1 branch
BranchTrueFalseTotal
if $size > @$self 1 8 9
110 8 ▶ return $self->new(@$self[($#$self - ($size - 1)) .. $#$self]) if $size >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $size >= 0 4 4 8
111 4 return $self->new(@$self[(0 - $size) .. $#$self]);
112 }
113  
114 2 ▶sub tap {
Subroutine tap: called CC=2 SCAR=6.9
Pod undocumented
115 2 my ($self, $cb) = (shift, shift);
116 2 $_->$cb(@_) for $self;
117 2 return $self;
118 }
119  
120 64 ▶sub to_array { [@{shift()}] }
Subroutine to_array: called CC=1 SCAR=0.0
Pod undocumented
121  
122 7 ▶sub uniq {
Subroutine uniq: called CC=4 SCAR=13.9
Pod undocumented
123 7 my ($self, $cb) = (shift, shift);
124 7 my %seen;
125 7 ▶ return $self->new(grep { my $r = $_->$cb(@_); !$seen{defined $r ? $r : ''}++ } @$self) if $cb;
Branch: 2 branches
BranchTrueFalseTotal
if $cb 3 4 7
defined $r ? : 11 1 12
126 4 ▶ return $self->new(grep { !$seen{defined $_ ? $_ : ''}++ } @$self);
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 26 1 27
127 }
128  
129 2 ▶sub with_roles {
Subroutine with_roles: called CC=4 SCAR=14.0
Pod undocumented
130 2 croak 'Role::Tiny 2.000001+ is required for roles' unless ROLES;
131 2 my ($self, @roles) = @_;
132
133 return Role::Tiny->create_class_with_roles($self,
134 2 ▶ map { /^\+(.+)$/ ? "${self}::Role::$1" : $_ } @roles)
Branch: 2 branches
BranchTrueFalseTotal
unless my $class = builtin::blessed($self) 1 1 2
/^\+(.+)$/ ? : 0 1 1
135 unless my $class = blessed $self;
136
137 return Role::Tiny->apply_roles_to_object($self,
138 1 ▶ map { /^\+(.+)$/ ? "${class}::Role::$1" : $_ } @roles);
Branch: 1 branch
BranchTrueFalseTotal
/^\+(.+)$/ ? : 0 1 1
139 }
140  
141 16 ▶sub _flatten {
Subroutine _flatten: called CC=2 SCAR=6.9
142 16 ▶ map { _ref($_) ? _flatten(@$_) : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
_ref($_) ? : 11 30 41
143 }
144  
145 # For perl < 5.8.9
146 0 ▶sub _reduce (&@) {
Subroutine _reduce: not called CC=3 SCAR=20.6
147 0 my $code = shift;
148  
149 0 ▶ return shift unless @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 0 0 0
150  
151 0 my $caller = caller;
152  
153 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
154  
155 0 local (*{"${caller}::a"}, *{"${caller}::b"}) = (\my $x, \my $y);
156  
157 0 $x = shift;
158 0 foreach my $e (@_) {
159 0 $y = $e;
160 0 $x = $code->();
161 }
162  
163 0 $x;
164 }
165  
166 41 ▶sub _ref { ref $_[0] eq 'ARRAY' || blessed $_[0] && $_[0]->isa(__PACKAGE__) }
Subroutine _ref: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "ARRAY" or builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__) 3 38 41
Condition100%6/6
ref $_[0] eq 'ARRAY' || builtin::blessed($_[0]) && $_[0]->isa(__PACKAGE__)
l!l&&r!l&&!r
3830
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
!ll&&!rl&&r
2648
MC/DC100%3/3
ref $_[0] eq 'ARRAY' || builtin::blessed($_[0]) && $_[0]->isa(__PACKAGE__)
ref $_[0] eq 'ARRAY' builtin::blessed($_[0]) $_[0]->isa(__PACKAGE__)
Truth table100%4/4
A || B and C
A= ref $_[0] eq 'ARRAY'B= builtin::blessed($_[0])C= $_[0]->isa(__PACKAGE__)
ABCresult
1XX1
0111
00X0
0100
167  
168 3 1;
169  
170 =for Pod::Coverage *EVERYTHING*
171  
172 =cut
« DOM58.pm ↑ Summary