| 1 | package DOM::Tiny::_Collection; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use List::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use constant REDUCE => ($] >= 5.008009 ? \&List::Util::reduce : \&_reduce); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our $VERSION = '0.003'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 663 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 663 | ▶ | return bless [@_], ref $class || $class; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | sub TO_JSON { [@{shift()}] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TO_JSON: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | sub compact { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compact: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | return $self->new(grep { defined && (ref || length) } @$self); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $_ && (ref $_ || length $_)
ref $_ or length $_
MC/DC66%2/3
defined $_ && (ref $_ || length $_)
defined $_
ref $_
length $_
Truth table75%3/4
A && B or C
A= defined $_B= ref $_C= length $_
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | sub each { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 113 | ▶ | my ($self, $cb) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
each: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 113 | ▶ | return @$self unless $cb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 103 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 103 | $_->$cb($i++) for @$self; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 103 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | sub first { | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 74 | ▶ | my ($self, $cb) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 74 | ▶ | return $self->[0] unless $cb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 11 | ▶ | return List::Util::first { $_ =~ $cb } @$self if ref $cb eq 'Regexp'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 10 | ▶ | return List::Util::first { $_->$cb(@_) } @$self; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | ▶ | sub flatten { $_[0]->new(_flatten(@{$_[0]})) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flatten: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | sub grep { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 9 | ▶ | my ($self, $cb) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
grep: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | ▶ | return $self->new(grep { $_ =~ $cb } @$self) if ref $cb eq 'Regexp'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | return $self->new(grep { $_->$cb(@_) } @$self); | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | sub join { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 37 | ▶ | join +(defined($_[1]) ? $_[1] : ''), map {"$_"} @{$_[0]}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
join: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 18 | ▶ | sub last { shift->[-1] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | sub map { | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 37 | ▶ | my ($self, $cb) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
map: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 37 | return $self->new(map { $_->$cb(@_) } @$self); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | sub reduce { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reduce: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | @_ = (@_, @$self); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | goto &{REDUCE()}; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 8 | ▶ | sub reverse { $_[0]->new(reverse @{$_[0]}) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reverse: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | sub shuffle { $_[0]->new(List::Util::shuffle @{$_[0]}) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shuffle: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 46 | ▶ | sub size { scalar @{$_[0]} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | sub slice { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
slice: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 8 | return $self->new(@$self[@_]); | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | sub sort { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | ▶ | my ($self, $cb) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sort: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 6 | ▶ | return $self->new(sort @$self) unless $cb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 4 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | my @sorted = sort { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | local (*{"${caller}::a"}, *{"${caller}::b"}) = (\$a, \$b); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 12 | $a->$cb($b); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } @$self; | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | return $self->new(@sorted); | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | sub tap { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | my ($self, $cb) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tap: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | $_->$cb(@_) for $self; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 37 | ▶ | sub to_array { [@{shift()}] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_array: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | sub uniq { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 5 | ▶ | my ($self, $cb) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uniq: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 5 | my %seen; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 5 | ▶ | return $self->new(grep { !$seen{$_->$cb(@_)}++ } @$self) if $cb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | return $self->new(grep { !$seen{$_}++ } @$self); | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | sub _flatten { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 16 | ▶ | map { _ref($_) ? _flatten(@$_) : $_ } @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_flatten: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | # For perl < 5.8.9 | ||||||||||||||||||||||||||||||||||||||||||
| 110 | sub _reduce (&@) { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my $code = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reduce: not called CC=3 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return shift unless @_ > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | local(*{$caller."::a"}) = \my $x; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | local(*{$caller."::b"}) = \my $y; | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $x = shift; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | foreach (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $y = $_; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $x = $code->(); | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $x; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 41 | ▶ | sub _ref { ref $_[0] eq 'ARRAY' || blessed $_[0] && $_[0]->isa(__PACKAGE__) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ref: called CC=3 SCAR=11.0
Branch: 1 branch
Condition100%6/6
ref $_[0] eq 'ARRAY' || builtin::blessed($_[0]) && $_[0]->isa(__PACKAGE__)
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__)
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__)
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | =for Pod::Coverage *EVERYTHING* | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | =cut | ||||||||||||||||||||||||||||||||||||||||||