NewsExtractor.pm

filter: Statementstmt 68.8% 31 / 45 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 69.2% 9 / 13 Podpod 0.0% 0 / 1 totaltotal 63.4% 40 / 63 CC 3 SCAR 12.2
CC
3
Cov
63%
download
12.0
__ANON__
2.0
__ANON__
2.0
CRAP 3.4
« NewsExtractor/SiteSpecificExtractor/talk_ltn_com_tw.pm ↑ Summary NewsExtractor/SiteSpecificExtractor/ctee_com_tw.pm »
1 package NewsExtractor;
2 1 our $VERSION = v0.45.0;
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Mojo::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Mojo::UserAgent::Transactor;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Types::Standard qw< Str >;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Types::URI qw< Uri >;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Importer 'NewsExtractor::TextUtil' => qw(u);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use NewsExtractor::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use NewsExtractor::Download;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 has url => ( required => 1, is => 'ro', isa => Uri, coerce => 1 );
17  
18 has user_agent_string => (
19 required => 1,
20 is => 'ro',
21 isa => Str,
22 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 0 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:93.0) Gecko/20100101 Firefox/93.0'
24 }
25 1 );
26  
27 0 ▶sub download {
Subroutine download: not called CC=3 SCAR=24.8
Pod undocumented
28 0 my NewsExtractor $self = shift;
29  
30 0 my $ua = Mojo::UserAgent->new()->transactor(
31 Mojo::UserAgent::Transactor->new()->name( $self->user_agent_string )
32 )->max_redirects(3);
33  
34 0 my ($error, $download);
35  
36 0 my $tx = $ua->get( "". $self->url );
37  
38 0 my $res;
39 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 0 $res = $tx->result
41 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 0 $error = NewsExtractor::Error->new(
43 is_exception => 0,
44 message => u($_),
45 )
46 0 };
47  
48 0 ▶ if ($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 0 0 0
49 0 ▶ if ($res->is_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_error) { } 0 0 0
50 0 $error = NewsExtractor::Error->new(
51 is_exception => 0,
52 message => u($res->message),
53 );
54 } else {
55 0 $download = NewsExtractor::Download->new( tx => $tx );
56 }
57 }
58 0 return ($error, $download);
59 }
60  
61 1 1;
62  
63 __END__
« NewsExtractor/SiteSpecificExtractor/talk_ltn_com_tw.pm ↑ Summary NewsExtractor/SiteSpecificExtractor/ctee_com_tw.pm »