line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
1700
|
use v5.14.0; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
132
|
|
2
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
130
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package OS::Package::Artifact::Role::Validate; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Provides the validation methods for Artifact role. |
7
|
|
|
|
|
|
|
our $VERSION = '0.2.7'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
14
|
use Digest::MD5; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
89
|
|
10
|
3
|
|
|
3
|
|
2637
|
use Digest::SHA; |
|
3
|
|
|
|
|
8577
|
|
|
3
|
|
|
|
|
140
|
|
11
|
3
|
|
|
3
|
|
21
|
use OS::Package::Log; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
259
|
|
12
|
3
|
|
|
3
|
|
15
|
use Path::Tiny; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
149
|
|
13
|
3
|
|
|
3
|
|
14
|
use Role::Tiny; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
24
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub validate { |
16
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
if ( defined $self->md5 ) { |
19
|
0
|
0
|
|
|
|
|
if ( !$self->validate_md5 ) { |
20
|
0
|
|
|
|
|
|
return 0; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
if ( defined $self->sha1 ) { |
25
|
0
|
0
|
|
|
|
|
if ( !$self->validate_sha1 ) { |
26
|
0
|
|
|
|
|
|
return 0; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
return 1; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub validate_md5 { |
34
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $md5 = Digest::MD5->new(); |
37
|
0
|
|
|
|
|
|
my $fh = path( $self->savefile )->openr; |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
$md5->addfile($fh) |
40
|
|
|
|
|
|
|
or |
41
|
|
|
|
|
|
|
$LOGGER->logcroak( sprintf 'cannot open file %s', $self->savefile ); |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if ( $md5->hexdigest eq $self->md5 ) { |
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
|
|
|
0
|
1
|
|
my $self = shift; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $sha = Digest::SHA->new; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$sha->addfile( $self->savefile ); |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if ( $sha->hexdigest eq $self->sha1 ) { |
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
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |