blib/lib/NewsExtractor/TXExtractor.pm

filter: Statementstmt 48.0% 12 / 25 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod n/a totaltotal 38.4% 15 / 39 CC 6 SCAR 33.4
CC
6
Cov
34%
_build_dom
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 28.3
« 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
BranchTrueFalseTotal
if ($tx->result->headers->content_type =~ /charset=(\S+)/) { } 0 0 0
elsif (my $el = $dom->at('meta[http-equiv="content-type" i]')) { } 0 0 0
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
BranchTrueFalseTotal
if ($el->attr("content") =~ /\;\s*charset=(\S+)/i) 0 0 0
28 0 $charset = $1;
29 }
30 }
31  
32 0 ▶ if ($charset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($charset) 0 0 0
33 0 my $enc = find_encoding( $charset );
34 0 ▶ if ($enc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc) 0 0 0
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;
« blib/lib/NewsExtractor/GenericExtractor.pm ↑ Summary blib/lib/NewsExtractor/SiteSpecificExtractor/www_mdnkids_com.pm »