| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::Google::Code::Role::HTMLTree; | 
| 2 | 12 |  |  | 12 |  | 9063 | use Any::Moose 'Role'; | 
|  | 12 |  |  |  |  | 24 |  | 
|  | 12 |  |  |  |  | 84 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 12 |  |  | 12 |  | 20563 | use HTML::TreeBuilder; | 
|  | 12 |  |  |  |  | 339701 |  | 
|  | 12 |  |  |  |  | 201 |  | 
| 5 | 12 |  |  | 12 |  | 644 | use Params::Validate qw(:all); | 
|  | 12 |  |  |  |  | 38 |  | 
|  | 12 |  |  |  |  | 3595 |  | 
| 6 | 12 |  |  | 12 |  | 79 | use Scalar::Util qw/blessed/; | 
|  | 12 |  |  |  |  | 29 |  | 
|  | 12 |  |  |  |  | 4366 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | sub html_tree { | 
| 9 | 36 |  |  | 36 | 1 | 73 | my $self = shift; | 
| 10 | 36 |  |  |  |  | 2078 | my %args = validate( @_, { html => { type => SCALAR } } ); | 
| 11 | 36 |  |  |  |  | 411 | my $tree = HTML::TreeBuilder->new; | 
| 12 | 36 |  |  |  |  | 8827 | $tree->parse_content($args{html}); | 
| 13 | 36 |  |  |  |  | 1296259 | $tree->elementify; | 
| 14 | 36 |  |  |  |  | 3786 | return $tree; | 
| 15 |  |  |  |  |  |  | } | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub html_tree_contains { | 
| 18 | 0 |  |  | 0 | 1 |  | 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 | 0 |  |  |  |  | if ( blessed $args{html} ) { | 
| 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 | 0 |  |  |  |  | if ( $args{look_down} ) { | 
| 42 | 0 |  |  |  |  |  | ($part) = $tree->look_down( @{ $args{look_down} } ); | 
|  | 0 |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 0 |  | 0 |  |  |  | my $text = $part && $part->as_text; | 
| 47 | 0 | 0 |  |  |  |  | $tree->delete if $need_delete; | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 0 | 0 |  |  |  |  | return unless defined $text; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 0 | 0 |  |  |  |  | return 1 if $text eq $args{as_text}; | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 0 | 0 | 0 |  |  |  | if ( ( ref $args{as_text} eq 'Regexp' ) && ( my @captures = | 
| 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 | 0 |  |  |  |  | return wantarray ? ( 1, @captures ) : 1; | 
| 60 |  |  |  |  |  |  | } | 
| 61 | 0 |  |  |  |  |  | return; | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 | 12 |  |  | 12 |  | 90 | no Any::Moose; | 
|  | 12 |  |  |  |  | 22 |  | 
|  | 12 |  |  |  |  | 126 |  | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | 1; | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | __END__ |