| 1 | package HTML5::DOM::TokenList; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use HTML5::DOM::Node; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | use overload | ||||||||||||||||||||||||||||
| 8 | 0 | ▶ | '""' => sub { $_[0]->text }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | '@{}' => sub { $_[0]->_items }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 0 | ▶ | 'bool' => sub { 1 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | fallback => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub new { | ||||||||||||||||||||||||||||
| 14 | 17 | ▶ | my ($class, $node, $attr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 17 | my $self = { | |||||||||||||||||||||||||||
| 16 | node => $node, | ||||||||||||||||||||||||||||
| 17 | attr => $attr | ||||||||||||||||||||||||||||
| 18 | }; | ||||||||||||||||||||||||||||
| 19 | 17 | bless $self, $class; | |||||||||||||||||||||||||||
| 20 | 17 | return $self; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub text { | ||||||||||||||||||||||||||||
| 24 | 4 | ▶ | my $attr = $_[0]->{node}->attr($_[0]->{attr}); | ||||||||||||||||||||||||||
|
Subroutine
text: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 4 | ▶ | return defined $attr ? $attr : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub _items { | ||||||||||||||||||||||||||||
| 29 | 9 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_items: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||
| 30 | 9 | my $attr = $self->{node}->attr($self->{attr}); | |||||||||||||||||||||||||||
| 31 | 9 | ▶ | if (defined $attr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 9 | my @items = split(/\s+/, $attr); | |||||||||||||||||||||||||||
| 33 | 9 | ▶ | return [] if (scalar(@items) == 1 && $items[0] eq ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar @items == 1 and $items[0] eq ""
MC/DC0%0/2
scalar @items == 1 and $items[0] eq ""
scalar @items == 1
$items[0] eq ""
Truth table66%2/3
A and B
A= scalar @items == 1B= $items[0] eq ""
| |||||||||||||||||||||||||||||
| 34 | 9 | return \@items; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 0 | return []; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub item { | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my ($self, $index) = @_; | ||||||||||||||||||||||||||
|
Subroutine
item: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 0 | return $self->_items()->[$index]; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | sub length { | ||||||||||||||||||||||||||||
| 45 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
length: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 2 | return scalar(@{$self->_items()}); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub has { | ||||||||||||||||||||||||||||
| 50 | 8 | ▶ | my ($self, $token) = @_; | ||||||||||||||||||||||||||
|
Subroutine
has: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 8 | my $attr = $self->{node}->attr($self->{attr}); | |||||||||||||||||||||||||||
| 52 | 8 | ▶ | if (defined $attr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 8 | return $attr =~ /(\s|^)\Q$token\E(\s|$)/; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 0 | return 0; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub contains { shift->has(@_) } | ||||||||||||||||||||||||||
|
Subroutine
contains: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub add { | ||||||||||||||||||||||||||||
| 61 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 2 | my $items = $self->_items(); | |||||||||||||||||||||||||||
| 63 | 2 | for my $token (@_) { | |||||||||||||||||||||||||||
| 64 | 8 | ▶ | next if ($self->has($token)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 5 | push @$items, $token; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 2 | $self->{node}->attr($self->{attr}, join(" ", @$items)); | |||||||||||||||||||||||||||
| 68 | 2 | return $self; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub remove { | ||||||||||||||||||||||||||||
| 72 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
remove: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | 2 | my $attr = $self->{node}->attr($self->{attr}); | |||||||||||||||||||||||||||
| 74 | 2 | ▶ | if (defined $attr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 2 | for my $token (@_) { | |||||||||||||||||||||||||||
| 76 | 7 | $attr =~ s/(\s|^)\Q$token\E(\s|$)/ /g; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 2 | $attr =~ s/^\s+|\s+$//; | |||||||||||||||||||||||||||
| 79 | 2 | $self->{node}->attr($self->{attr}, $attr); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 2 | return $self; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub replace { | ||||||||||||||||||||||||||||
| 85 | 1 | ▶ | my ($self, $key, $value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
replace: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 1 | my $attr = $self->{node}->attr($self->{attr}); | |||||||||||||||||||||||||||
| 87 | 1 | ▶ | if (defined $attr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 1 | $attr =~ s/(\s|^)\Q$key\E(\s|$)/$1$value$2/g; | |||||||||||||||||||||||||||
| 89 | 1 | $self->{node}->attr($self->{attr}, $attr); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 1 | return $self; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | sub toggle { | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my ($self, $token, $force) = @_; | ||||||||||||||||||||||||||
|
Subroutine
toggle: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my $state = defined $force ? $force : !$self->has($token); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $state ? $self->add($token) : $self->remove($token); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | return $state; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | sub each { | ||||||||||||||||||||||||||||
| 102 | 1 | ▶ | my ($self, $callback) = @_; | ||||||||||||||||||||||||||
|
Subroutine
each: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | 1 | my $index = 0; | |||||||||||||||||||||||||||
| 104 | 1 | for my $node (@{$self->_items()}) { | |||||||||||||||||||||||||||
| 105 | 4 | $callback->($node, $index); | |||||||||||||||||||||||||||
| 106 | 4 | ++$index; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 1 | return $self; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 3 | 1; | |||||||||||||||||||||||||||