blib/lib/Pinto/Role/UserAgent.pm

filter: Statementstmt 64.0% 32 / 50 Branchbran 37.5% 3 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 64.2% 9 / 14 Podpod 50.0% 2 / 4 totaltotal 60.5% 46 / 76 CC 5 SCAR 9.6
CC
5
Cov
60%
mirror_temporary
6.0
mirror
4.7
head
2.0
CRAP 2.6
« blib/lib/App/Pinto/Command/kill.pm ↑ Summary blib/lib/Pinto/Schema/ResultSet/Registration.pm »
1 # ABSTRACT: Something that makes network requests
2  
3 package Pinto::Role::UserAgent;
4  
5 72 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 72 ▶use MooseX::MarkAsMethods ( autoclean => 1 );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 72 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 72 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 72 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 72 ▶use HTTP::Status qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 72 ▶use Pinto::Globals;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 72 ▶use Pinto::Util qw(debug throw tempdir make_uri);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #-----------------------------------------------------------------------------
17  
18 72 our $VERSION = '0.14'; # VERSION
19  
20 #-----------------------------------------------------------------------------
21  
22  
23 60 ▶sub mirror {
Subroutine mirror: called CC=4 SCAR=15.5
Pod documented
24 60 my ( $self, $from, $to ) = @_;
25  
26 60 $from = make_uri($from);
27 60 $to = file($to);
28  
29 60 ▶ $to->parent->mkpath if not -e $to->parent;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $to->parent 59 1 60
30 60 my $response = $Pinto::Globals::UA->mirror( $from => $to );
31
32 60 ▶ return 1 if $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $response->is_success 60 0 60
33 0 ▶ return 0 if $response->code == HTTP_NOT_MODIFIED;
Branch: 1 branch
BranchTrueFalseTotal
if $response->code == 304 0 0 0
34  
35 0 throw "Failed to mirror $from: " . $response->status_line;
36 }
37  
38 #------------------------------------------------------------------------------
39  
40  
41 0 ▶sub mirror_temporary {
Subroutine mirror_temporary: not called CC=2 SCAR=17.9
Pod documented
42 0 my ( $self, $uri ) = @_;
43  
44 0 $uri = URI->new( $uri )->canonical;
45 0 my $path = file( $uri->path );
46 0 ▶ return $path if $uri->scheme() eq 'file';
Branch: 1 branch
BranchTrueFalseTotal
if $uri->scheme eq "file" 0 0 0
47  
48 0 my $base = $path->basename;
49 0 my $tempfile = file( tempdir, $base );
50  
51 0 $self->mirror( $uri => $tempfile );
52  
53 0 return file($tempfile);
54 }
55  
56 #------------------------------------------------------------------------------
57 # TODO: Consider a better interface to the UA
58  
59 0 ▶sub head {
Subroutine head: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my ($self, @args) = @_;
61  
62 # TODO: Argument check?
63 0 ▶ debug sub { $args[0]->as_string(0) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 return $Pinto::Globals::UA->head(@args);
65 }
66  
67 #------------------------------------------------------------------------------
68 # TODO: Consider a better interface to the UA
69  
70 0 ▶sub request {
Subroutine request: not called CC=1 SCAR=6.9
Pod undocumented
71 0 my ($self, @args) = @_;
72  
73 # TODO: Argument check?
74 0 ▶ debug sub { $args[0]->as_string(0) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 0 return $Pinto::Globals::UA->request(@args);
76 }
77  
78 #-----------------------------------------------------------------------------
79 72 1;
80  
81 __END__
« blib/lib/App/Pinto/Command/kill.pm ↑ Summary blib/lib/Pinto/Schema/ResultSet/Registration.pm »