File Coverage

blib/lib/Metabrik/File/Hash.pm
Criterion Covered Total %
statement 9 50 18.0
branch 0 24 0.0
condition 0 12 0.0
subroutine 3 8 37.5
pod 1 5 20.0
total 13 99 13.1


line stmt bran cond sub pod time code
1             #
2             # $Id$
3             #
4             # file::hash Brik
5             #
6             package Metabrik::File::Hash;
7 1     1   787 use strict;
  1         3  
  1         30  
8 1     1   5 use warnings;
  1         11  
  1         40  
9              
10 1     1   7 use base qw(Metabrik);
  1         2  
  1         640  
11              
12             sub brik_properties {
13             return {
14 0     0 1   revision => '$Revision$',
15             tags => [ qw(unstable sha sha1 sha256 sha512 md5 md5sum sum) ],
16             author => 'GomoR ',
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 0     0 0   my $self = shift;
35 0           my ($input) = @_;
36              
37 0   0       $input ||= $self->input;
38 0 0         $self->brik_help_run_undef_arg('sha1', $input) or return;
39 0 0         $self->brik_help_run_file_not_found('sha1', $input) or return;
40              
41 0           eval("use Crypt::Digest::SHA1 qw(sha1_file_hex);");
42 0 0         if ($@) {
43 0           chomp($@);
44 0           return $self->log->error("sha1: unable to load function: $@");
45             }
46              
47 0           return Crypt::Digest::SHA1::sha1_file_hex($input);
48             }
49              
50             sub sha256 {
51 0     0 0   my $self = shift;
52 0           my ($input) = @_;
53              
54 0   0       $input ||= $self->input;
55 0 0         $self->brik_help_run_undef_arg('sha256', $input) or return;
56 0 0         $self->brik_help_run_file_not_found('sha256', $input) or return;
57              
58 0           eval("use Crypt::Digest::SHA256 qw(sha256_file_hex);");
59 0 0         if ($@) {
60 0           chomp($@);
61 0           return $self->log->error("sha256: unable to load function: $@");
62             }
63              
64 0           return Crypt::Digest::SHA256::sha256_file_hex($input);
65             }
66              
67             sub sha512 {
68 0     0 0   my $self = shift;
69 0           my ($input) = @_;
70              
71 0   0       $input ||= $self->input;
72 0 0         $self->brik_help_run_undef_arg('sha512', $input) or return;
73 0 0         $self->brik_help_run_file_not_found('sha512', $input) or return;
74              
75 0           eval("use Crypt::Digest::SHA512 qw(sha512_file_hex);");
76 0 0         if ($@) {
77 0           chomp($@);
78 0           return $self->log->error("sha512: unable to load function: $@");
79             }
80              
81 0           return Crypt::Digest::SHA512::sha512_file_hex($input);
82             }
83              
84             sub md5 {
85 0     0 0   my $self = shift;
86 0           my ($input) = @_;
87              
88 0   0       $input ||= $self->input;
89 0 0         $self->brik_help_run_undef_arg('md5', $input) or return;
90 0 0         $self->brik_help_run_file_not_found('md5', $input) or return;
91              
92 0           eval("use Crypt::Digest::MD5 qw(md5_file_hex);");
93 0 0         if ($@) {
94 0           chomp($@);
95 0           return $self->log->error("md5: unable to load function: $@");
96             }
97              
98 0           return Crypt::Digest::MD5::md5_file_hex($input);
99             }
100              
101             1;
102              
103             __END__