blib/lib/HTML5/DOM/Collection.pm

filter: Statementstmt 18.1% 10 / 55 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 18.7% 3 / 16 Podpod 0.0% 0 / 11 totaltotal 14.2% 13 / 91 CC 9 SCAR 19.6
CC
9
Cov
16%
map
20.0
new
12.0
each
6.0
CRAP 7.1
« blib/lib/HTML5/DOM/TokenList.pm ↑ Summary blib/lib/HTML5/DOM/Tree.pm »
1 package HTML5::DOM::Collection;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 use overload
6 0 ▶ '""' => sub { shift->html },
Subroutine __ANON__: not called CC=1 SCAR=6.9
7 0 ▶ 'bool' => sub { 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
8 1 ▶ fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub new {
11 0 ▶ my ($class, $nodes) = @_;
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
12 0 ▶ $nodes = [] if (!$nodes || ref($nodes) ne 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if not $nodes or ref $nodes ne "ARRAY" 0 0 0
Condition0%0/3
not $nodes or ref $nodes ne "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $nodes or ref $nodes ne "ARRAY"
not $nodes ref $nodes ne "ARRAY"
Truth table0%0/3
not(A) or B
A= not $nodesB= ref $nodes ne "ARRAY"
ABresult
1X1
011
000
13 0 return bless $nodes, $class;
14 }
15  
16 sub add {
17 0 ▶ my $self = shift;
Subroutine add: not called CC=1 SCAR=6.9
Pod undocumented
18 0 push @{$self}, shift;
19 0 return $self;
20 }
21  
22 0 ▶sub length { scalar(@{shift()}); }
Subroutine length: not called CC=1 SCAR=6.9
Pod undocumented
23 0 ▶sub first { shift->[0] }
Subroutine first: not called CC=1 SCAR=6.9
Pod undocumented
24 0 ▶sub last { shift->[-1] }
Subroutine last: not called CC=1 SCAR=6.9
Pod undocumented
25 0 ▶sub item { shift->[shift] }
Subroutine item: not called CC=1 SCAR=6.9
Pod undocumented
26 0 ▶sub array { [@{shift()}] }
Subroutine array: not called CC=1 SCAR=6.9
Pod undocumented
27  
28 sub each {
29 0 ▶ my ($self, $callback) = @_;
Subroutine each: not called CC=2 SCAR=17.9
Pod undocumented
30 0 my $index = 0;
31 0 for my $node (@{shift()}) {
32 0 $callback->($node, $index);
33 0 ++$index;
34 }
35 0 return $self;
36 }
37  
38 sub map {
39 0 ▶ my $self = shift;
Subroutine map: not called CC=4 SCAR=30.0
Pod undocumented
40 0 my @result;
41 0 ▶ if (ref($_[0]) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'CODE') { } 0 0 0
42 0 my $method = shift;
43 0 my $index = 0;
44 0 for my $node (@$self) {
45 0 push @result, $method->($node, $index, @_);
46 0 ++$index;
47 }
48 } else {
49 0 my $method = shift;
50 0 for my $node (@$self) {
51 0 push @result, $node->$method(@_);
52 }
53 }
54 0 return HTML5::DOM::Collection->new(\@result);
55 }
56  
57 sub text {
58 0 ▶ my @nodes;
Subroutine text: not called CC=2 SCAR=17.9
Pod undocumented
59 0 for my $node (@{shift()}) {
60 0 push @nodes, $node->text;
61 }
62 0 return join("", @nodes);
63 }
64  
65 sub html {
66 0 ▶ my @nodes;
Subroutine html: not called CC=2 SCAR=17.9
Pod undocumented
67 0 for my $node (@{shift()}) {
68 0 push @nodes, $node->html;
69 }
70 0 return join("", @nodes);
71 }
72  
73 1 1;
« blib/lib/HTML5/DOM/TokenList.pm ↑ Summary blib/lib/HTML5/DOM/Tree.pm »