line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::File::Role::Digest; |
2
|
1
|
|
|
1
|
|
596
|
use Mojo::Base -strict, -role, -signatures; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
requires 'open'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3867
|
use Carp 'croak'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
9
|
1
|
|
|
1
|
|
4
|
use Digest::MD5; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
10
|
1
|
|
|
1
|
|
5
|
use Digest::SHA; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use constant SUPPORTS_QX => |
13
|
1
|
|
|
1
|
|
5
|
!!(eval { require Digest::QuickXor; Digest::QuickXor->VERSION('0.03'); 1 }); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
433
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# methods |
16
|
|
|
|
|
|
|
|
17
|
4
|
|
|
4
|
1
|
4923
|
sub md5_sum ($self) { |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
7
|
|
18
|
4
|
|
|
|
|
34
|
return $self->_calcdigest(Digest::MD5->new); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
4
|
|
|
4
|
1
|
3126
|
sub quickxor_hash ($self) { |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
4
|
|
22
|
4
|
|
|
|
|
338
|
croak 'Digest::QuickXor not available!' unless SUPPORTS_QX; |
23
|
0
|
|
|
|
|
0
|
return $self->_calcdigest(Digest::QuickXor->new, 'b64digest'); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
4
|
1
|
2581
|
sub sha1_sum ($self) { |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
5
|
|
27
|
4
|
|
|
|
|
20
|
return $self->_calcdigest(Digest::SHA->new(1)); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
4
|
|
|
4
|
1
|
2700
|
sub sha256_sum ($self) { |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
5
|
|
31
|
4
|
|
|
|
|
23
|
return $self->_calcdigest(Digest::SHA->new(256)); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# internal methods |
35
|
|
|
|
|
|
|
|
36
|
12
|
|
|
12
|
|
113
|
sub _calcdigest ($self, $module, $fn = 'hexdigest') { |
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
14
|
|
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
12
|
|
37
|
12
|
|
|
|
|
31
|
return $module->addfile($self->open('<'))->$fn; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=encoding utf8 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Mojo::File::Role::Digest - A role for Mojo::File to calculate digests |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 SYNOPSIS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# single file |
51
|
|
|
|
|
|
|
use Mojo::File 'path'; |
52
|
|
|
|
|
|
|
my $file = path($path)->with_roles('+Digest'); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# modified file class |
55
|
|
|
|
|
|
|
use Mojo::File; |
56
|
|
|
|
|
|
|
my $class = Mojo::File->with_roles('+Digest'); |
57
|
|
|
|
|
|
|
my $file = $class->new($path); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$file->md5_sum; |
60
|
|
|
|
|
|
|
$file->quickxor_hash; # requires Digest::QuickXor |
61
|
|
|
|
|
|
|
$file->sha1_sum; |
62
|
|
|
|
|
|
|
$file->sha256_sum; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
L is a role for L to calculate MD5, SHA1, SHA256, and QuickXor digests. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 APPLY ROLE |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
use Mojo::File 'path'; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $file = path($path); |
73
|
|
|
|
|
|
|
my $file_with_digest = $file->with_roles('+Digest'); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Apply to a single L object. See L. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
use Mojo::File; |
78
|
|
|
|
|
|
|
my $class = Mojo::File->with_roles('+Digest'); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $file1 = $class->new($path1); |
81
|
|
|
|
|
|
|
my $file2 = $class->new($path2); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Create a modified file class with applied digest role. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 METHODS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 md5_sum |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$string = $file->md5_sum; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Returns the MD5 sum of the file in hexadecimal form. See L. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 quickxor_hash |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$string = $file->quickxor_hash; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Returns the base64 encoded QuickXorHash of the file. See L. |
98
|
|
|
|
|
|
|
Requires L 0.03 or higher. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 sha1_sum |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$string = $file->sha1_sum; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Returns the SHA1 sum of the file in hexadecimal form. See L. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 sha256_sum |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$string = $file->sha256_sum; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Returns the SHA256 sum of the file in hexadecimal form. See L. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHOR & COPYRIGHT |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
© 2019 by Tekki (Rolf Stöckli). |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SEE ALSO |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
L, L, L, L, L, L. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |