Code/Role/HTMLTree.pm

filter: Statementstmt 55.0% 22 / 40 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 85.7% 6 / 7 Podpod 100% 2 / 2 totaltotal 41.1% 30 / 73 CC 10 SCAR 42.4
CC
10
Cov
37%
html_tree_contains
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 69.1
« Code/Issue/Util.pm ↑ Summary Code/Issue/Comment.pm »
1 package Net::Google::Code::Role::HTMLTree;
2 12 ▶use Any::Moose 'Role';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 12 ▶use HTML::TreeBuilder;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Params::Validate qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 36 ▶sub html_tree {
Subroutine html_tree: called CC=1 SCAR=0.0
Pod documented
9 36 my $self = shift;
10 36 my %args = validate( @_, { html => { type => SCALAR } } );
11 36 my $tree = HTML::TreeBuilder->new;
12 36 $tree->parse_content($args{html});
13 36 $tree->elementify;
14 36 return $tree;
15 }
16  
17 0 ▶sub html_tree_contains {
Subroutine html_tree_contains: not called CC=10 SCAR=47.0
Pod documented
18 0 my $self = shift;
19 0 my %args = validate(
20 @_,
21 {
22 html => { type => SCALAR },
23 look_down => { type => ARRAYREF, optional => 1 },
24  
25 # SCALARREF is for the regex
26 as_text => { type => SCALAR | SCALARREF },
27 }
28 );
29  
30 0 my $tree;
31 my $need_delete;
32 0 ▶ if ( blessed $args{html} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($args{'html'})) { } 0 0 0
33 0 $tree = $args{html};
34 }
35 else {
36 0 $tree = $self->html_tree( html => $args{html} );
37 0 $need_delete = 1;
38 }
39  
40 0 my $part = $tree;
41 0 ▶ if ( $args{look_down} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"look_down"}) 0 0 0
42 0 ($part) = $tree->look_down( @{ $args{look_down} } );
43 }
44  
45  
46 0 ▶ my $text = $part && $part->as_text;
Condition0%0/3
$part && $part->as_text
!ll&&!rl&&r
000
MC/DC0%0/2
$part && $part->as_text
$part $part->as_text
Truth table0%0/3
A && B
A= $partB= $part->as_text
ABresult
0X0
100
111
47 0 ▶ $tree->delete if $need_delete;
Branch: 1 branch
BranchTrueFalseTotal
if $need_delete 0 0 0
48  
49 0 ▶ return unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 0 0
50  
51 0 ▶ return 1 if $text eq $args{as_text};
Branch: 1 branch
BranchTrueFalseTotal
if $text eq $args{"as_text"} 0 0 0
52  
53 0 ▶ if ( ( ref $args{as_text} eq 'Regexp' ) && ( my @captures =
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"as_text"} eq "Regexp" and my(@captures) = $text =~ /$args{"as_text"}/) 0 0 0
Condition0%0/3
ref $args{"as_text"} eq "Regexp" and my(@captures) = $text =~ /$args{"as_text"}/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $args{"as_text"} eq "Regexp" and my(@captures) = $text =~ /$args{"as_text"}/
ref $args{"as_text"} eq "Regexp" my(@captures) = $text =~ /$args{"as_text"}/
Truth table0%0/3
A and B
A= ref $args{"as_text"} eq "Regexp"B= my(@captures) = $text =~ /$args{"as_text"}/
ABresult
0X0
100
111
54 $text =~ $args{as_text} ) )
55 {
56 # note, if there's no captures at all but the string matches,
57 # @captures will be set to (1), so don't use @captures unless you
58 # know there's some capture in the regex
59 0 ▶ return wantarray ? ( 1, @captures ) : 1;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
60 }
61 0 return;
62 }
63  
64 12 ▶no Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66 12 1;
67  
68 __END__
« Code/Issue/Util.pm ↑ Summary Code/Issue/Comment.pm »