| 1 | package Hash::MD5; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 3 | ▶ | use 5.006; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 3 | ▶ | use warnings FATAL => 'all'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 3 | ▶ | use Digest::MD5 qw(md5_hex); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 3 | ▶ | use vars qw($VERSION @ISA @EXPORT_OK); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 3 | ▶ | use Data::Dumper; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 3 | require Exporter; | |||||||||||||
| 11 | 3 | *import = \&Exporter::import; | |||||||||||||
| 12 | 3 | @EXPORT_OK = qw(sum_hash sum_array); | |||||||||||||
| 13 | |||||||||||||||
| 14 | ############################################################################### | ||||||||||||||
| 15 | ############## PRIVATE SUBS ###################### | ||||||||||||||
| 16 | ############################################################################### | ||||||||||||||
| 17 | sub _sort_keys{ | ||||||||||||||
| 18 | 9 | ▶ | my ( $hashref ) = @_; | ||||||||||||
|
Subroutine
_sort_keys: called CC=4 SCAR=14.6
| |||||||||||||||
| 19 | 9 | my $number_of_elements = scalar(keys %$hashref); | |||||||||||||
| 20 | 9 | my $ret = "{"; | |||||||||||||
| 21 | 9 | foreach ( sort { $a cmp $b } keys %$hashref ) { | |||||||||||||
| 22 | 18 | ▶ | if(ref $hashref->{$_} eq 'HASH'){ | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 23 | 0 | $ret = $ret.qq~$_:~._sort_keys($hashref->{$_}); | |||||||||||||
| 24 | }elsif(ref $hashref->{$_} eq 'ARRAY'){ | ||||||||||||||
| 25 | 0 | $ret = $ret.qq~$_:~._sort_array($hashref->{$_}); | |||||||||||||
| 26 | }else{ | ||||||||||||||
| 27 | 18 | $ret = $ret.qq~$_:"$hashref->{$_}"~; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | 18 | $ret = $ret.","; | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | 9 | return $ret . "lenght:". $number_of_elements . "}"; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | sub _sort_array{ | ||||||||||||||
| 35 | 6 | ▶ | my ( $arrayref ) = @_; | ||||||||||||
|
Subroutine
_sort_array: called CC=4 SCAR=14.0
| |||||||||||||||
| 36 | 6 | my $number_of_elements = scalar( @$arrayref ); | |||||||||||||
| 37 | 6 | my $ret = "["; | |||||||||||||
| 38 | 6 | foreach ( @$arrayref ) { | |||||||||||||
| 39 | 19 | ▶ | if(ref $_ eq 'HASH'){ | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 40 | 3 | $ret = $ret._sort_keys($_) ; | |||||||||||||
| 41 | }elsif(ref $_ eq 'ARRAY'){ | ||||||||||||||
| 42 | 0 | $ret = $ret._sort_array($_) ; | |||||||||||||
| 43 | }else{ | ||||||||||||||
| 44 | 16 | $ret = $ret.qq~"$_"~; | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | 19 | $ret = $ret.","; | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | 6 | 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 | 3 | 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 | ▶ | my ( $arg ) = @_; | ||||||||||||
|
Subroutine
sum_hash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 92 | 6 | return md5_hex( _sort_keys($arg) ); | |||||||||||||
| 93 | } | ||||||||||||||
| 94 | |||||||||||||||
| 95 | =head2 sum_array | ||||||||||||||
| 96 | |||||||||||||||
| 97 | =cut | ||||||||||||||
| 98 | |||||||||||||||
| 99 | sub sum_array{ | ||||||||||||||
| 100 | 6 | ▶ | my ( $arg ) = @_; | ||||||||||||
|
Subroutine
sum_array: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 101 | 6 | return md5_hex( _sort_array($arg) ); | |||||||||||||
| 102 | } | ||||||||||||||
| 103 | |||||||||||||||
| 104 | =head1 AUTHOR | ||||||||||||||
| 105 | |||||||||||||||
| 106 | Mario Zieschang, C<< <mario.zieschang at combase.de> >> | ||||||||||||||
| 107 | |||||||||||||||
| 108 | =head1 BUGS | ||||||||||||||
| 109 | |||||||||||||||
| 110 | Please report any bugs or feature requests to C<bug-hash-md5 at rt.cpan.org>, or through | ||||||||||||||
| 111 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Hash-MD5>. 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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Hash-MD5> | ||||||||||||||
| 122 | |||||||||||||||
| 123 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||
| 124 | |||||||||||||||
| 125 | L<http://annocpan.org/dist/Hash-MD5> | ||||||||||||||
| 126 | |||||||||||||||
| 127 | =item * CPAN Ratings | ||||||||||||||
| 128 | |||||||||||||||
| 129 | L<http://cpanratings.perl.org/d/Hash-MD5> | ||||||||||||||
| 130 | |||||||||||||||
| 131 | =item * Search CPAN | ||||||||||||||
| 132 | |||||||||||||||
| 133 | L<http://search.cpan.org/dist/Hash-MD5/> | ||||||||||||||
| 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<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||
| 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 | 3 | 1; # End of Hash::MD5 | |||||||||||||