« blib/lib/NewsExtractor/GenericExtractor.pm
↑ Summary
blib/lib/NewsExtractor/SiteSpecificExtractor/www_mdnkids_com.pm »
| 1 | package NewsExtractor::TXExtractor; | ||||||||||||||
| 2 | 1 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 1 | ▶ | use Types::Standard qw( InstanceOf ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use Encode 'find_encoding'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 1 | has tx => ( | |||||||||||||
| 7 | required => 0, | ||||||||||||||
| 8 | is => 'ro', | ||||||||||||||
| 9 | isa => InstanceOf['Mojo::Transaction::HTTP'] | ||||||||||||||
| 10 | ); | ||||||||||||||
| 11 | |||||||||||||||
| 12 | 1 | has dom => ( | |||||||||||||
| 13 | required => 0, | ||||||||||||||
| 14 | isa => InstanceOf['Mojo::DOM'], | ||||||||||||||
| 15 | is => 'lazy', | ||||||||||||||
| 16 | builder => 1, | ||||||||||||||
| 17 | ); | ||||||||||||||
| 18 | |||||||||||||||
| 19 | sub _build_dom { | ||||||||||||||
| 20 | 0 | ▶ | my $tx = $_[0]->tx; | ||||||||||||
|
Subroutine
_build_dom: not called CC=6 SCAR=37.4
| |||||||||||||||
| 21 | 0 | my $dom = $tx->result->dom; | |||||||||||||
| 22 | |||||||||||||||
| 23 | 0 | my $charset; | |||||||||||||
| 24 | 0 | ▶ | if ($tx->result->headers->content_type =~ /charset=(\S+)/) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 25 | 0 | $charset = $1; | |||||||||||||
| 26 | } elsif (my $el = $dom->at('meta[http-equiv="content-type" i]')) { | ||||||||||||||
| 27 | 0 | ▶ | if ($el->attr("content") =~ /\;\s*charset=(\S+)/i) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 28 | 0 | $charset = $1; | |||||||||||||
| 29 | } | ||||||||||||||
| 30 | } | ||||||||||||||
| 31 | |||||||||||||||
| 32 | 0 | ▶ | if ($charset) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 33 | 0 | my $enc = find_encoding( $charset ); | |||||||||||||
| 34 | 0 | ▶ | if ($enc) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 35 | 0 | my $body = $enc->decode($tx->result->body); | |||||||||||||
| 36 | 0 | $dom = Mojo::DOM->new($body); | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 0 | return $dom; | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | |||||||||||||||
| 43 | 1 | 1; | |||||||||||||