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

filter: Statementstmt 46.8% 22 / 47 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod 100% 3 / 3 totaltotal 43.2% 32 / 74 SCAR 32.1
CC
8
Cov
36%
validate
30.0
validate_md5
12.0
validate_sha1
6.0
CRAP 24.7
« blib/lib/OS/Package/Factory.pm ↑ Summary blib/lib/OS/Package/Role/Prune.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::Validate;
5  
6 # ABSTRACT: Provides the validation methods for Artifact role.
7 3 our $VERSION = '0.2.6'; # VERSION
8  
9 3 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Digest::SHA;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use OS::Package::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub validate {
16 0 ▶ my $self = shift;
Subroutine validate: not called CC=5 SCAR=34.0
Pod documented
17  
18 0 ▶ if ( defined $self->md5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->md5) 0 0 0
19 0 ▶ if ( !$self->validate_md5 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->validate_md5) 0 0 0
20 0 return 0;
21 }
22 }
23  
24 0 ▶ if ( defined $self->sha1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->sha1) 0 0 0
25 0 ▶ if ( !$self->validate_sha1 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->validate_sha1) 0 0 0
26 0 return 0;
27 }
28 }
29  
30 0 return 1;
31 }
32  
33 sub validate_md5 {
34 0 ▶ my $self = shift;
Subroutine validate_md5: not called CC=3 SCAR=24.8
Pod documented
35  
36 0 my $md5 = Digest::MD5->new();
37 0 my $fh = path( $self->savefile )->openr;
38  
39 0 ▶ $md5->addfile($fh)
Branch: 1 branch
BranchTrueFalseTotal
$md5->addfile($fh) or $OS::Package::Artifact::Role::Validate::LOGGER->logcroak(sprintf("cannot open file %s", $self->savefile)) 0 0 0
40 or
41 $LOGGER->logcroak( sprintf 'cannot open file %s', $self->savefile );
42  
43 0 ▶ if ( $md5->hexdigest eq $self->md5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($md5->hexdigest eq $self->md5) 0 0 0
44 0 $LOGGER->info( sprintf 'md5 checksum ok: %s', $self->distfile );
45 0 return 1;
46 }
47  
48 0 $LOGGER->fatal( sprintf 'md5 checksum bad: %s', $self->distfile );
49 0 return 0;
50 }
51  
52 sub validate_sha1 {
53 0 ▶ my $self = shift;
Subroutine validate_sha1: not called CC=2 SCAR=17.9
Pod documented
54  
55 0 my $sha = Digest::SHA->new;
56  
57 0 $sha->addfile( $self->savefile );
58  
59 0 ▶ if ( $sha->hexdigest eq $self->sha1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sha->hexdigest eq $self->sha1) 0 0 0
60 0 $LOGGER->info( sprintf 'sha1 checksum ok: %s', $self->distfile );
61 0 return 1;
62 }
63  
64 0 $LOGGER->fatal( sprintf 'sha1 checksum bad: %s', $self->distfile );
65 0 return 0;
66  
67 }
68  
69 3 1;
70  
71 __END__
72  
73 =pod
74  
75 =encoding UTF-8
76  
77 =head1 NAME
78  
79 OS::Package::Artifact::Role::Validate - Provides the validation methods for Artifact role.
80  
81 =head1 VERSION
82  
83 version 0.2.6
84  
85 =head1 METHODS
86  
87 =head2 validate
88  
89 Provides the validate method which is a wrapper for validate_md5 and validate_sha1.
90  
91 =head2 validate_md5
92  
93 Validates the MD5 hash of the downloaded save file to the application configuration
94 file.
95  
96 =head2 validate_sha1
97  
98 Validates the SHA1 hash of the downloaded save file to the application configuration
99 file.
100  
101 =head1 AUTHOR
102  
103 James F Wilkus <jfwilkus@cpan.org>
104  
105 =head1 COPYRIGHT AND LICENSE
106  
107 This software is Copyright (c) 2014 by James F Wilkus.
108  
109 This is free software, licensed under:
110  
111 The (three-clause) BSD License
112  
113 =cut
« blib/lib/OS/Package/Factory.pm ↑ Summary blib/lib/OS/Package/Role/Prune.pm »