File Coverage

blib/lib/PerlIO/via/MD5.pm
Criterion Covered Total %
statement 22 22 100.0
branch 8 10 80.0
condition n/a
subroutine 5 5 100.0
pod 1 3 33.3
total 36 40 90.0


line stmt bran cond sub pod time code
1             package PerlIO::via::MD5;
2              
3             $VERSION= '0.08';
4              
5             # be as strict as possible
6 1     1   58877 use strict;
  1         2  
  1         26  
7              
8             # modules that we need
9 1     1   5 use Digest::MD5 (); # no need to pollute this namespace
  1         1  
  1         275  
10              
11             # initializations
12             my %allowed= ( digest => 1, hexdigest => 1, b64digest => 1 );
13             my $method= 'hexdigest';
14              
15             # satisfy -require-
16             1;
17              
18             #-------------------------------------------------------------------------------
19             #
20             # Methods for settings that will be used by the objects
21             #
22             #-------------------------------------------------------------------------------
23             # IN: 1 class (ignored)
24             # 2 new setting for method
25             # OUT: 1 current setting for eol
26              
27             sub method {
28 3     3 1 79 shift;
29              
30             # set new value if given
31 3 100       10 if (@_) {
32 2 50       7 die "Invalid digest method '$_[0]'" unless $allowed{$_[0]};
33 2         3 $method= shift;
34             }
35              
36 3         15 return $method;
37             } #method
38              
39             #-------------------------------------------------------------------------------
40             #
41             # Standard Perl features
42             #
43             #-------------------------------------------------------------------------------
44             # IN: 1 class
45             # 2 mode string (ignored)
46             # 3 file handle of PerlIO layer below (ignored)
47             # OUT: 1 blessed object
48              
49             sub PUSHED {
50              
51             # not reading
52 3 50   3 0 708 return -1 if $_[1] ne 'r';
53              
54 3         127 return bless [ Digest::MD5->new, $method ], $_[0];
55             } #PUSHED
56              
57             #-------------------------------------------------------------------------------
58             # IN: 1 instantiated object
59             # 2 handle to read from
60             # OUT: 1 empty string (when still busy) or the digest string (when done)
61              
62             sub FILL {
63              
64             # still reading file
65 51     51 0 138 my $line= readline( $_[1] );
66 51 100       90 if ( defined($line) ) {
    100          
67 45         95 $_[0]->[0]->add($line);
68              
69             # nothing to be returned yet
70 45         81 return '';
71             }
72              
73             # end of data reached, we have MD5 object still
74             elsif ( $_[0]->[0] ) {
75 3         4 my ( $object, $method )= @{ $_[0] };
  3         8  
76 3         5 $_[0]->[0]= '';
77              
78             # return result of digest
79 3         25 return $object->$method;
80             }
81              
82             # huh?, end of data without MD5 object, empty file?
83 3         18 return undef;
84             } #FILL
85              
86             #-------------------------------------------------------------------------------
87              
88             __END__