| 1 | package HTML5::DOM::TokenList; | ||||||||||||||||||||||||||||
| 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 | 1 | ▶ | 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 | 0 | ▶ | '@{}' => sub { $_[0]->_items }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 10 | 0 | ▶ | 'bool' => sub { 1 }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | fallback => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub new { | ||||||||||||||||||||||||||||
| 14 | 0 | ▶ | my ($class, $node, $attr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 0 | my $self = { | |||||||||||||||||||||||||||
| 16 | node => $node, | ||||||||||||||||||||||||||||
| 17 | attr => $attr | ||||||||||||||||||||||||||||
| 18 | }; | ||||||||||||||||||||||||||||
| 19 | 0 | bless $self, $class; | |||||||||||||||||||||||||||
| 20 | 0 | return $self; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub text { | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my $attr = $_[0]->{node}->attr($_[0]->{attr}); | ||||||||||||||||||||||||||
|
Subroutine
text: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | return defined $attr ? $attr : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub _items { | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_items: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 30 | 0 | my $attr = $self->{node}->attr($self->{attr}); | |||||||||||||||||||||||||||
| 31 | 0 | ▶ | if (defined $attr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 0 | my @items = split(/\s+/, $attr); | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | return [] if (scalar(@items) == 1 && $items[0] eq ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/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 table0%0/3
A and B
A= scalar @items == 1B= $items[0] eq ""
| |||||||||||||||||||||||||||||
| 34 | 0 | 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 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
length: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 0 | return scalar(@{$self->_items()}); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub has { | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my ($self, $token) = @_; | ||||||||||||||||||||||||||
|
Subroutine
has: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 0 | my $attr = $self->{node}->attr($self->{attr}); | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (defined $attr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | 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 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 0 | my $items = $self->_items(); | |||||||||||||||||||||||||||
| 63 | 0 | for my $token (@_) { | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | next if ($self->has($token)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | push @$items, $token; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 0 | $self->{node}->attr($self->{attr}, join(" ", @$items)); | |||||||||||||||||||||||||||
| 68 | 0 | return $self; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub remove { | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
remove: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | 0 | my $attr = $self->{node}->attr($self->{attr}); | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | if (defined $attr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | for my $token (@_) { | |||||||||||||||||||||||||||
| 76 | 0 | $attr =~ s/(\s|^)\Q$token\E(\s|$)/ /g; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 0 | $attr =~ s/^\s+|\s+$//; | |||||||||||||||||||||||||||
| 79 | 0 | $self->{node}->attr($self->{attr}, $attr); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 0 | return $self; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub replace { | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my ($self, $key, $value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
replace: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 0 | my $attr = $self->{node}->attr($self->{attr}); | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | if (defined $attr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | $attr =~ s/(\s|^)\Q$key\E(\s|$)/$1$value$2/g; | |||||||||||||||||||||||||||
| 89 | 0 | $self->{node}->attr($self->{attr}, $attr); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 0 | 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 | 0 | ▶ | my ($self, $callback) = @_; | ||||||||||||||||||||||||||
|
Subroutine
each: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 103 | 0 | my $index = 0; | |||||||||||||||||||||||||||
| 104 | 0 | for my $node (@{$self->_items()}) { | |||||||||||||||||||||||||||
| 105 | 0 | $callback->($node, $index); | |||||||||||||||||||||||||||
| 106 | 0 | ++$index; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 0 | return $self; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | 1; | |||||||||||||||||||||||||||