| 1 | package WWW::Pastebin::PastebinCa::Retrieve; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '1.001001'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use base 'WWW::Pastebin::Base::Retrieve'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use HTML::TokeParser::Simple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use HTML::Entities; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | sub _make_uri_and_id { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | my ( $self, $id ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_uri_and_id: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | my ( $private ) = $id =~ m{(?:http://)? (?:www\.)? (.+?) pastebin\.ca}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | $private = '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | unless defined $private; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | $id =~ s{ ^ \s+ | (?:http://)? (?:www\.)?.*? pastebin\.ca/ | \s+ $}{}gxi; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | return ( URI->new("http://${private}pastebin.ca/$id"), $id ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | sub _parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | my ( $self, $content ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=35 SCAR=57.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | return $self->_set_error( 'Nothing to parse (empty document retrieved)' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $content and length $content
MC/DC0%0/2
defined $content and length $content
defined $content
length $content
Truth table33%1/3
A and B
A= defined $contentB= length $content
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | unless defined $content and length $content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | my $parser = HTML::TokeParser::Simple->new( \$content ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my %data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my %nav = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | level => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | get_lang => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | get_name => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | get_date => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | get_desc => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | while ( my $t = $parser->get_token ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 908 | ▶ | if ( $t->is_start_tag('h2') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 13 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | #and defined $t->get_attr('class') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | #and $t->get_attr('class') eq 'first' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $nav{level} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ▶ | elsif ( $nav{level} == 1 and $t->is_start_tag('dt') ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$nav{"level"} == 1 and $t->is_start_tag("dt")
MC/DC0%0/2
$nav{"level"} == 1 and $t->is_start_tag("dt")
$nav{"level"} == 1
$t->is_start_tag("dt")
Truth table33%1/3
A and B
A= $nav{"level"} == 1B= $t->is_start_tag("dt")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | @nav{ qw(level get_name) } = (2, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ▶ | elsif ( $nav{get_name} == 1 and $t->is_text ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$nav{"get_name"} == 1 and $t->is_text
MC/DC0%0/2
$nav{"get_name"} == 1 and $t->is_text
$nav{"get_name"} == 1
$t->is_text
Truth table33%1/3
A and B
A= $nav{"get_name"} == 1B= $t->is_text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $data{name} = $t->as_is; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $nav{get_name} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ▶ | elsif ( $t->is_start_tag('p') and defined $t->get_attr('id') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$t->is_start_tag("p") and defined $t->get_attr("id") and $t->get_attr("id") eq "des"
$t->is_start_tag("p") and defined $t->get_attr("id")
MC/DC0%0/3
$t->is_start_tag("p") and defined $t->get_attr("id") and $t->get_attr("id") eq "des"
$t->is_start_tag("p")
defined $t->get_attr("id")
$t->get_attr("id") eq "des"
Truth table75%3/4
A and B and C
A= $t->is_start_tag("p")B= defined $t->get_attr("id")C= $t->get_attr("id") eq "des"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | and $t->get_attr('id') eq 'des' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $nav{get_desc} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ▶ | elsif ( $nav{get_desc} and $t->is_text ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$nav{"get_desc"} and $t->is_text
MC/DC0%0/2
$nav{"get_desc"} and $t->is_text
$nav{"get_desc"}
$t->is_text
Truth table33%1/3
A and B
A= $nav{"get_desc"}B= $t->is_text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $data{desc} = $t->as_is; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $nav{get_desc} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ▶ | elsif ( $nav{level} == 2 and $t->is_start_tag('dd') ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$nav{"level"} == 2 and $t->is_start_tag("dd")
MC/DC0%0/2
$nav{"level"} == 2 and $t->is_start_tag("dd")
$nav{"level"} == 2
$t->is_start_tag("dd")
Truth table33%1/3
A and B
A= $nav{"level"} == 2B= $t->is_start_tag("dd")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $nav{get_date} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $nav{level}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ▶ | elsif ( $nav{get_date} and $t->is_text ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$nav{"get_date"} and $t->is_text
MC/DC0%0/2
$nav{"get_date"} and $t->is_text
$nav{"get_date"}
$t->is_text
Truth table33%1/3
A and B
A= $nav{"get_date"}B= $t->is_text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $data{post_date} = $t->as_is; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $data{post_date} =~ s/\s+/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $data{post_date} =~ s/ //g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $nav{get_date} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $nav{level} = 7; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ▶ | elsif ( $nav{level} == 7 and $t->is_start_tag('span') ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$nav{"level"} == 7 and $t->is_start_tag("span")
MC/DC0%0/2
$nav{"level"} == 7 and $t->is_start_tag("span")
$nav{"level"} == 7
$t->is_start_tag("span")
Truth table33%1/3
A and B
A= $nav{"level"} == 7B= $t->is_start_tag("span")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $nav{level}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ▶ | elsif ( $t->is_start_tag('textarea') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$t->is_start_tag("textarea") and defined $t->get_attr("name") and $t->get_attr("name") eq "content"
$t->is_start_tag("textarea") and defined $t->get_attr("name")
MC/DC0%0/3
$t->is_start_tag("textarea") and defined $t->get_attr("name") and $t->get_attr("name") eq "content"
$t->is_start_tag("textarea")
defined $t->get_attr("name")
$t->get_attr("name") eq "content"
Truth table25%1/4
A and B and C
A= $t->is_start_tag("textarea")B= defined $t->get_attr("name")C= $t->get_attr("name") eq "content"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | and defined $t->get_attr('name') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | and $t->get_attr('name') eq 'content' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $nav{get_paste} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ▶ | elsif ( $nav{get_paste} and $t->is_text ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$nav{"get_paste"} and $t->is_text
MC/DC0%0/2
$nav{"get_paste"} and $t->is_text
$nav{"get_paste"}
$t->is_text
Truth table33%1/3
A and B
A= $nav{"get_paste"}B= $t->is_text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $data{content} = $t->as_is; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $nav{get_paste} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $nav{get_lang} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ▶ | elsif ( $nav{get_lang} == 1 and $t->is_start_tag('select') ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$nav{"get_lang"} == 1 and $t->is_start_tag("select")
MC/DC0%0/2
$nav{"get_lang"} == 1 and $t->is_start_tag("select")
$nav{"get_lang"} == 1
$t->is_start_tag("select")
Truth table33%1/3
A and B
A= $nav{"get_lang"} == 1B= $t->is_start_tag("select")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $nav{get_lang} = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | ▶ | elsif ( $nav{get_lang} == 2 and $t->is_start_tag('option') | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$nav{"get_lang"} == 2 and $t->is_start_tag("option") and $t->get_attr("selected")
$nav{"get_lang"} == 2 and $t->is_start_tag("option")
MC/DC0%0/3
$nav{"get_lang"} == 2 and $t->is_start_tag("option") and $t->get_attr("selected")
$nav{"get_lang"} == 2
$t->is_start_tag("option")
$t->get_attr("selected")
Truth table25%1/4
A and B and C
A= $nav{"get_lang"} == 2B= $t->is_start_tag("option")C= $t->get_attr("selected")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | and $t->get_attr('selected') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $nav{get_lang} = 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ▶ | elsif ( $nav{get_lang} == 3 and $t->is_text ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$nav{"get_lang"} == 3 and $t->is_text
MC/DC0%0/2
$nav{"get_lang"} == 3 and $t->is_text
$nav{"get_lang"} == 3
$t->is_text
Truth table33%1/3
A and B
A= $nav{"get_lang"} == 3B= $t->is_text
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $data{language} = $t->as_is; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $nav{success} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | unless ( $nav{success} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | my $message = "Failed to parse paste.. "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | $message .= $nav{level} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | ? "\$nav{level} == $nav{level}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | : "that paste ID doesn't seem to exist"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | return $self->_set_error( $message ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | decode_entities( $_ ) for values %data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $self->content( $data{content} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return \%data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||