| 1 | package URI::Title::HTML; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | $URI::Title::HTML::VERSION = '1.903'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use HTML::Entities; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | our $CAN_USE_ENCODE; | |||||||||||||||||||||||||||||||||||||||||
| 9 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | eval { require Encode; Encode->import('decode') }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | $CAN_USE_ENCODE = !$@; | |||||||||||||||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | sub types {( | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | 'text/html', | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
types: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 'default', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | )} | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | sub title { | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | my ($class, $url, $data, $type, $cset) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
title: called CC=21 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | my $title; | |||||||||||||||||||||||||||||||||||||||||
| 23 | my $special_case; | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | my $default_match = '<title.*?>(.+?)</title'; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | # special case for the iTMS. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | if ( $INC{'URI/Title/iTMS.pm'} and $url =~ m!phobos.apple.com! and $data =~ m!(itms://[^']*)! ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$INC{"URI/Title/iTMS.pm"} and $url =~ /phobos.apple.com/ and $data =~ m[(itms://[^']*)]
$INC{"URI/Title/iTMS.pm"} and $url =~ /phobos.apple.com/
MC/DC0%0/3
$INC{"URI/Title/iTMS.pm"} and $url =~ /phobos.apple.com/ and $data =~ m[(itms://[^']*)]
$INC{"URI/Title/iTMS.pm"}
$url =~ /phobos.apple.com/
$data =~ m[(itms://[^']*)]
Truth table25%1/4
A and B and C
A= $INC{"URI/Title/iTMS.pm"}B= $url =~ /phobos.apple.com/C= $data =~ m[(itms://[^']*)]
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | return URI::Title::iTMS->title($1); | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # TODO - work this out from the headers of the HTML | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | if ($data =~ /charset=\"?([\w-]+)/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $cset = lc($1); | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | if ( $CAN_USE_ENCODE ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | $data = eval { decode('utf-8', $data, 1) } || eval { decode($cset, $data, 1) } || $data; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
eval {
do {
&decode('utf-8', $data, 1)
}
} || eval {
do {
&decode($cset, $data, 1)
}
} || $data
eval {
do {
&decode("utf-8", $data, 1)
}
} or eval {
do {
&decode($cset, $data, 1)
}
}
MC/DC0%0/3
eval {
do {
&decode('utf-8', $data, 1)
}
} || eval {
do {
&decode($cset, $data, 1)
}
} || $data
eval {
do {
&decode("utf-8", $data, 1)
}
}
eval {
do {
&decode($cset, $data, 1)
}
}
$data
Truth table25%1/4
A or B || C
A= eval {
do {
&decode("utf-8", $data, 1)
}
}B= eval {
do {
&decode($cset, $data, 1)
}
}C= $data
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | my $found_title; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | if ($url) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | if ($url =~ /use\.perl\.org\/~([^\/]+).*journal\/\d/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $special_case = '<FONT FACE="geneva,verdana,sans-serif" SIZE="1"><B>(.+?)<'; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $title = "use.perl journal of $1 - "; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | } elsif ($url =~ /(pants\.heddley\.com|dailychump\.org).*#(.*)$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $id = $2; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $special_case = 'id="a'.$id.'.*?></a>(.+?)<'; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $title = "pants daily chump - "; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | } elsif ($url =~ /paste\.husk\.org/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $special_case = 'Summary: (.+?)<'; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $title = "paste - "; | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | } elsif ($url =~ /twitter.com\/(.*?)\/status(es)?\/\d+/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $special_case = '<p class="js-tweet-text tweet-text">([^\<]+)'; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $title = "twitter - "; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | } elsif ($url =~ /independent\.co\.uk/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $special_case = '<h1 class=head1>(.+?)<'; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | } elsif ($url =~ /www\.hs\.fi\/english\/article/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $special_case = '<h1>(.+?)</h1>'; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | ▶ | } elsif ($url =~ /google.com/i and $data =~ /calc_img/) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$url =~ /google.com/i and $data =~ /calc_img/
MC/DC0%0/2
$url =~ /google.com/i and $data =~ /calc_img/
$url =~ /google.com/i
$data =~ /calc_img/
Truth table33%1/3
A and B
A= $url =~ /google.com/iB= $data =~ /calc_img/
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | # google can be used as a calculator. Try to find the result. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $special_case = 'calc_img.*<td nowrap>(.+?)</td'; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | if (!$found_title and $special_case) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $found_title and $special_case
MC/DC0%0/2
not $found_title and $special_case
not $found_title
$special_case
Truth table33%1/3
not(A) and B
A= not $found_titleB= $special_case
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ($found_title) = $data =~ /$special_case/ims; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | if (!$found_title) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ($found_title) = $data =~ /$default_match/ims; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | return unless $found_title; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | $found_title =~ s/<sup>(.+?)<\/sup>/^$1/g; # for the google math output | |||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | $found_title =~ s/<.*?>//g; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | $title .= $found_title; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | $title =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | $title =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | $title =~ s/\n+//g; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | $title =~ s/\s+/ /g; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | #use Devel::Peek; | ||||||||||||||||||||||||||||||||||||||||||
| 94 | #Dump( $title ); | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | $title = decode_entities($title); | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | #Dump( $title ); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | # decode nasty number-encoded entities. Mostly works | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | $title =~ s/(&\#(\d+);?)/chr($2)/eg; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | return $title; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | __END__ | ||||||||||||||||||||||||||||||||||||||||||