File/Hash.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« File/Find.pm ↑ Summary File/Ini.pm »
1 #
2 # $Id$
3 #
4 # file::hash Brik
5 #
6 package Metabrik::File::Hash;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable sha sha1 sha256 sha512 md5 md5sum sum) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
17 license => 'http://opensource.org/licenses/BSD-3-Clause',
18 attributes => {
19 input => [ qw(file) ],
20 },
21 commands => {
22 sha1 => [ qw(input|OPTIONAL) ],
23 sha256 => [ qw(input|OPTIONAL) ],
24 sha512 => [ qw(input|OPTIONAL) ],
25 md5 => [ qw(input|OPTIONAL) ],
26 },
27 require_modules => {
28 'Crypt::Digest' => [ ],
29 },
30 };
31 }
32  
33 sub sha1 {
34 my $self = shift;
35 my ($input) = @_;
36  
37 $input ||= $self->input;
38 $self->brik_help_run_undef_arg('sha1', $input) or return;
39 $self->brik_help_run_file_not_found('sha1', $input) or return;
40  
41 eval("use Crypt::Digest::SHA1 qw(sha1_file_hex);");
42 if ($@) {
43 chomp($@);
44 return $self->log->error("sha1: unable to load function: $@");
45 }
46  
47 return Crypt::Digest::SHA1::sha1_file_hex($input);
48 }
49  
50 sub sha256 {
51 my $self = shift;
52 my ($input) = @_;
53  
54 $input ||= $self->input;
55 $self->brik_help_run_undef_arg('sha256', $input) or return;
56 $self->brik_help_run_file_not_found('sha256', $input) or return;
57  
58 eval("use Crypt::Digest::SHA256 qw(sha256_file_hex);");
59 if ($@) {
60 chomp($@);
61 return $self->log->error("sha256: unable to load function: $@");
62 }
63  
64 return Crypt::Digest::SHA256::sha256_file_hex($input);
65 }
66  
67 sub sha512 {
68 my $self = shift;
69 my ($input) = @_;
70  
71 $input ||= $self->input;
72 $self->brik_help_run_undef_arg('sha512', $input) or return;
73 $self->brik_help_run_file_not_found('sha512', $input) or return;
74  
75 eval("use Crypt::Digest::SHA512 qw(sha512_file_hex);");
76 if ($@) {
77 chomp($@);
78 return $self->log->error("sha512: unable to load function: $@");
79 }
80  
81 return Crypt::Digest::SHA512::sha512_file_hex($input);
82 }
83  
84 sub md5 {
85 my $self = shift;
86 my ($input) = @_;
87  
88 $input ||= $self->input;
89 $self->brik_help_run_undef_arg('md5', $input) or return;
90 $self->brik_help_run_file_not_found('md5', $input) or return;
91  
92 eval("use Crypt::Digest::MD5 qw(md5_file_hex);");
93 if ($@) {
94 chomp($@);
95 return $self->log->error("md5: unable to load function: $@");
96 }
97  
98 return Crypt::Digest::MD5::md5_file_hex($input);
99 }
100  
101 1;
102  
103 __END__
« File/Find.pm ↑ Summary File/Ini.pm »