| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
$part && $part->as_text
$part
$part->as_text
Truth table0%0/3
A && B
A= $partB= $part->as_text
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $tree->delete if $need_delete; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return unless defined $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return 1 if $text eq $args{as_text}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ( ( ref $args{as_text} eq 'Regexp' ) && ( my @captures = | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $args{"as_text"} eq "Regexp" and my(@captures) = $text =~ /$args{"as_text"}/
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"}/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||