File Coverage

lib/Hash/MD5.pm
Criterion Covered Total %
statement 40 43 93.0
branch 5 8 62.5
condition n/a
subroutine 10 10 100.0
pod 2 2 100.0
total 57 63 90.4


line stmt bran cond sub pod time code
1             package Hash::MD5;
2              
3 3     3   36107 use 5.006;
  3         9  
  3         91  
4 3     3   10 use strict;
  3         4  
  3         84  
5 3     3   23 use warnings FATAL => 'all';
  3         4  
  3         117  
6 3     3   11 use Digest::MD5 qw(md5_hex);
  3         3  
  3         150  
7 3     3   11 use vars qw($VERSION @ISA @EXPORT_OK);
  3         4  
  3         166  
8 3     3   1643 use Data::Dumper;
  3         18351  
  3         1339  
9              
10             require Exporter;
11             *import = \&Exporter::import;
12             @EXPORT_OK = qw(sum_hash sum_array);
13              
14             ###############################################################################
15             ############## PRIVATE SUBS ######################
16             ###############################################################################
17             sub _sort_keys{
18 9     9   11 my ( $hashref ) = @_;
19 9         14 my $number_of_elements = scalar(keys %$hashref);
20 9         8 my $ret = "{";
21 9         40 foreach ( sort { $a cmp $b } keys %$hashref ) {
  9         18  
22 18 50       43 if(ref $hashref->{$_} eq 'HASH'){
    50          
23 0         0 $ret = $ret.qq~$_:~._sort_keys($hashref->{$_});
24             }elsif(ref $hashref->{$_} eq 'ARRAY'){
25 0         0 $ret = $ret.qq~$_:~._sort_array($hashref->{$_});
26             }else{
27 18         26 $ret = $ret.qq~$_:"$hashref->{$_}"~;
28             }
29 18         20 $ret = $ret.",";
30             }
31 9         42 return $ret . "lenght:". $number_of_elements . "}";
32             }
33              
34             sub _sort_array{
35 6     6   7 my ( $arrayref ) = @_;
36 6         5 my $number_of_elements = scalar( @$arrayref );
37 6         4 my $ret = "[";
38 6         9 foreach ( @$arrayref ) {
39 19 100       26 if(ref $_ eq 'HASH'){
    50          
40 3         5 $ret = $ret._sort_keys($_) ;
41             }elsif(ref $_ eq 'ARRAY'){
42 0         0 $ret = $ret._sort_array($_) ;
43             }else{
44 16         17 $ret = $ret.qq~"$_"~;
45             }
46 19         19 $ret = $ret.",";
47             }
48 6         28 return $ret . $number_of_elements ."]";
49             }
50              
51             =pod
52              
53             =head1 NAME
54              
55             Hash::MD5 - MD5 checksum for choosen hashref
56              
57             =head1 VERSION
58              
59             Version 0.04
60              
61             =cut
62              
63             our $VERSION = '0.04';
64              
65              
66             =head1 SYNOPSIS
67              
68             use Hash::MD5 qw(sum_hash);
69            
70             ...
71             my $hashref = {some => 'hashref'};
72             print sum_hash( $hashref ), $/;
73             ...
74              
75              
76              
77             use Hash::MD5 qw(sum_array);
78            
79             ...
80             my $arrayref = ['some', 'arrayref'];
81             print sum_array( $arrayref ), $/;
82             ...
83              
84             =head1 SUBROUTINES/METHODS
85              
86             =head2 sum_hash
87              
88             =cut
89              
90             sub sum_hash{
91 6     6 1 973 my ( $arg ) = @_;
92 6         11 return md5_hex( _sort_keys($arg) );
93             }
94              
95             =head2 sum_array
96              
97             =cut
98              
99             sub sum_array{
100 6     6 1 942 my ( $arg ) = @_;
101 6         9 return md5_hex( _sort_array($arg) );
102             }
103              
104             =head1 AUTHOR
105              
106             Mario Zieschang, C<< >>
107              
108             =head1 BUGS
109              
110             Please report any bugs or feature requests to C, or through
111             the web interface at L. I will be notified, and then you'll
112             automatically be notified of progress on your bug as I make changes.
113              
114              
115             =head1 SUPPORT
116              
117             =over 4
118              
119             =item * RT: CPAN's request tracker (report bugs here)
120              
121             L
122              
123             =item * AnnoCPAN: Annotated CPAN documentation
124              
125             L
126              
127             =item * CPAN Ratings
128              
129             L
130              
131             =item * Search CPAN
132              
133             L
134              
135             =back
136              
137              
138             =head1 ACKNOWLEDGEMENTS
139              
140              
141             =head1 LICENSE AND COPYRIGHT
142              
143             Copyright 2015 Mario Zieschang.
144              
145             This program is free software; you can redistribute it and/or modify it
146             under the terms of the the Artistic License (2.0). You may obtain a
147             copy of the full license at:
148              
149             L
150              
151             Any use, modification, and distribution of the Standard or Modified
152             Versions is governed by this Artistic License. By using, modifying or
153             distributing the Package, you accept this license. Do not use, modify,
154             or distribute the Package, if you do not accept this license.
155              
156             If your Modified Version has been derived from a Modified Version made
157             by someone other than you, you are nevertheless required to ensure that
158             your Modified Version complies with the requirements of this license.
159              
160             This license does not grant you the right to use any trademark, service
161             mark, tradename, or logo of the Copyright Holder.
162              
163             This license includes the non-exclusive, worldwide, free-of-charge
164             patent license to make, have made, use, offer to sell, sell, import and
165             otherwise transfer the Package with respect to any patent claims
166             licensable by the Copyright Holder that are necessarily infringed by the
167             Package. If you institute patent litigation (including a cross-claim or
168             counterclaim) against any party alleging that the Package constitutes
169             direct or contributory patent infringement, then this Artistic License
170             to you shall terminate on the date that such litigation is filed.
171              
172             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
173             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
174             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
175             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
176             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
177             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
178             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
179             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
180              
181              
182             =cut
183              
184             1; # End of Hash::MD5