blib/lib/OS/Package/Artifact/Role/Download.pm

filter: Statementstmt 55.0% 22 / 40 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 52.6% 30 / 57 SCAR 21.9
CC
5
Cov
46%
download
30.0
BEGIN
1.0
BEGIN
1.0
CRAP 9.0
« blib/lib/OS/Package/Role/Build.pm ↑ Summary blib/lib/OS/Package/Role/Clean.pm »
1 3 ▶use v5.14.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package OS::Package::Artifact::Role::Download;
5  
6 3 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use OS::Package::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: Provides the download method for Artifact role.
13 3 our $VERSION = '0.2.6'; # VERSION
14  
15 sub download {
16  
17 0 ▶ my $self = shift;
Subroutine download: not called CC=5 SCAR=34.0
Pod documented
18  
19 0 ▶ if ( !$self->url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->url) 0 0 0
20 0 $LOGGER->debug('did not define url');
21 0 return 1;
22 }
23  
24 0 ▶ if ( path( $self->savefile )->exists ) {
Branch: 1 branch
BranchTrueFalseTotal
if (path($self->savefile)->exists) 0 0 0
25  
26 0 $LOGGER->info( sprintf 'distfile exists: %s', $self->savefile );
27  
28 0 ▶ if ( $self->validate ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->validate) { } 0 0 0
29 0 return 1;
30 }
31 else {
32 0 $LOGGER->warn( sprintf 'removing bad distfile: %s',
33 $self->savefile );
34 0 path( $self->savefile )->remove;
35 }
36 }
37  
38 0 $LOGGER->info( sprintf 'downloading: %s', $self->distfile );
39 0 $LOGGER->debug( sprintf 'saving to: %s', $self->savefile );
40  
41 0 my $response = HTTP::Tiny->new->get( $self->url );
42  
43 0 my $save_file = path( $self->savefile )->realpath;
44  
45 0 $save_file->spew( $response->{content} );
46  
47 0 ▶ if ( !$self->validate ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->validate) 0 0 0
48 0 $LOGGER->logcroak( sprintf 'cannot download: %s', $self->url );
49 }
50  
51 0 return 1;
52 }
53  
54 3 1;
55  
56 __END__
57  
58 =pod
59  
60 =encoding UTF-8
61  
62 =head1 NAME
63  
64 OS::Package::Artifact::Role::Download - Provides the download method for Artifact role.
65  
66 =head1 VERSION
67  
68 version 0.2.6
69  
70 =head1 METHODS
71  
72 =head2 download
73  
74 =head1 AUTHOR
75  
76 James F Wilkus <jfwilkus@cpan.org>
77  
78 =head1 COPYRIGHT AND LICENSE
79  
80 This software is Copyright (c) 2014 by James F Wilkus.
81  
82 This is free software, licensed under:
83  
84 The (three-clause) BSD License
85  
86 =cut
« blib/lib/OS/Package/Role/Build.pm ↑ Summary blib/lib/OS/Package/Role/Clean.pm »