Simple/Token/Tag/End.pm

filter: Statementstmt 84.7% 39 / 46 Branchbran 75.0% 6 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 78.5% 11 / 14 Podpod 100% 6 / 6 totaltotal 81.8% 63 / 77 CC 6 SCAR 5.9
CC
6
Cov
82%
rewrite_tag
3.1
_match_tag
2.1
_init
2.0
CRAP 1.8
« Simple/Token/Tag/Start.pm ↑ Summary Simple/Token/Tag.pm »
1 package HTML::TokeParser::Simple::Token::Tag::End;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 our $VERSION = '3.16';
6 5 ▶use base 'HTML::TokeParser::Simple::Token::Tag';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 my %TOKEN = (
9 tag => 1,
10 text => 2
11 );
12  
13 # in order to maintain the 'drop-in replacement' ability with HTML::TokeParser,
14 # we cannot alter the array refs. Thus we must store instance data here. Ugh.
15  
16 5 my %INSTANCE;
17  
18 32 ▶sub _init {
Subroutine _init: called CC=2 SCAR=6.9
19 32 my $self = shift;
20 32 ▶ if ('E' eq $self->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ('E' eq $self->[0]) { } 30 2 32
21 30 $INSTANCE{$self}{offset} = 0;
22 30 $INSTANCE{$self}{tag} = $self->[1];
23 }
24 else {
25 2 $INSTANCE{$self}{offset} = -1;
26 2 my $tag = $self->[0];
27 2 $tag =~ s/^\///;
28 2 $INSTANCE{$self}{tag} = $tag;
29 }
30 32 return $self;
31 }
32  
33 0 ▶sub _get_offset { return $INSTANCE{+shift}{offset} }
Subroutine _get_offset: not called CC=1 SCAR=6.9
34 20 ▶sub _get_text { return shift->[-1] }
Subroutine _get_text: called CC=1 SCAR=0.0
35  
36 13 ▶sub _get_tag {
Subroutine _get_tag: called CC=1 SCAR=0.0
37 13 my $self = shift;
38 13 return $INSTANCE{$self}{tag};
39 }
40  
41 23 ▶sub DESTROY { delete $INSTANCE{+shift} }
Subroutine DESTROY: called CC=1 SCAR=0.0
42  
43 5 ▶sub rewrite_tag {
Subroutine rewrite_tag: called CC=3 SCAR=11.2
Pod documented
44 5 my $self = shift;
45 # capture the final slash if the tag is self-closing
46 5 my ($self_closing) = $self->_get_text =~ m{(\s?/)>$};
47 5 ▶ $self_closing ||= '';
Condition50%1/2
$self_closing ||= ""
l!l
05
MC/DC0%0/1
$self_closing ||= ""
$self_closing
Truth table50%1/2
A
A= $self_closing
Aresult
11
00
48
49 5 ▶ my $first = $self->is_end_tag ? '/' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->is_end_tag ? : 5 0 5
50 5 my $tag = sprintf '<%s%s%s>', $first, $self->get_tag, $self_closing;
51 5 $self->_set_text($tag);
52 5 return $self;
53 }
54  
55 0 ▶sub return_text {
Subroutine return_text: not called CC=1 SCAR=6.9
Pod documented
56 0 require Carp;
57 0 Carp::carp('return_text() is deprecated. Use as_is() instead');
58 0 goto &as_is;
59 }
60  
61 15 ▶sub as_is {
Subroutine as_is: called CC=1 SCAR=0.0
Pod documented
62 15 return shift->_get_text;
63 }
64  
65 5 ▶sub get_tag {
Subroutine get_tag: called CC=1 SCAR=0.0
Pod documented
66 5 return shift->_get_tag;
67 }
68  
69 # is_foo methods
70  
71 0 ▶sub is_tag {
Subroutine is_tag: not called CC=1 SCAR=6.9
Pod documented
72 0 my $self = shift;
73 0 return $self->is_end_tag( @_ );
74 }
75  
76 15 ▶sub is_end_tag {
Subroutine is_end_tag: called CC=2 SCAR=6.9
Pod documented
77 15 my ($self, $tag) = @_;
78 15 ▶ return $tag ? $self->_match_tag($tag) : 1;
Branch: 1 branch
BranchTrueFalseTotal
$tag ? : 8 7 15
79 }
80  
81 8 ▶sub _match_tag {
Subroutine _match_tag: called CC=2 SCAR=7.2
82 8 my ($self, $tag) = @_;
83 8 ▶ if ('Regexp' eq ref $tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ('Regexp' eq ref $tag) { } 0 8 8
84 0 return $self->_get_tag =~ $tag;
85 }
86 else {
87 8 $tag = lc $tag;
88 8 $tag =~ s/^\///;
89 8 return $self->_get_tag eq $tag;
90 }
91 }
92  
93 5 1;
94  
95 __END__
« Simple/Token/Tag/Start.pm ↑ Summary Simple/Token/Tag.pm »