File Coverage

lib/Archive/Lha/Constants.pm
Criterion Covered Total %
statement 35 37 94.5
branch n/a
condition n/a
subroutine 6 8 75.0
pod n/a
total 41 45 91.1


line stmt bran cond sub pod time code
1             package Archive::Lha::Constants;
2            
3 18     18   111 use strict;
  18         64  
  18         743  
4 18     18   193 use warnings;
  18         66  
  18         3209  
5            
6             sub import {
7 60     60   831 my $class = shift;
8 60         162 my $caller = caller;
9            
10 60         287 my %size = ( CHAR => 1, UCHAR => 1, USHORT => 2 );
11 60         105 my %const;
12 60         247 foreach my $type ( keys %size ) {
13 180         467 $const{$type.'_SIZE'} = $size{$type};
14 180         432 $const{$type.'_BIT'} = $size{$type} * 8;
15 180         492 $const{$type.'_MAX'} = ( 1 << $size{$type} * 8 ) - 1;
16             }
17 60         337 $const{USHORT_CENTER} = int( ( $const{USHORT_MAX} + 1 ) / 2 );
18            
19             {
20 18     18   120 no strict 'refs';
  18         34  
  18         5541  
  60         167  
21 60         267 foreach my $key ( keys %const ) {
22 600     27   2157 *{"$caller\::$key"} = sub () { $const{$key} };
  600         2762  
  27         76  
23             }
24 60     0   195 *{"$caller\::_ushort"} = sub { shift() & $const{USHORT_MAX} };
  60         277  
  0         0  
25 60     0   221 *{"$caller\::_uchar"} = sub { shift() & $const{UCHAR_MAX} };
  60         259  
  0         0  
26 60         123 *{"$caller\::_bit_length"} = \&_bit_length;
  60         2410  
27             }
28             }
29            
30             sub _bit_length {
31 27     27   45 my $bits = shift;
32 27         38 my $length = 0;
33 27         66 while ( $bits ) { $bits >>= 1; $length++; }
  165         222  
  165         310  
34 27         76 return $length;
35             }
36            
37             1;
38            
39             __END__