File Coverage

lib/Archive/Lha/Stream/Hex.pm
Criterion Covered Total %
statement 28 28 100.0
branch 3 4 75.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 39 40 97.5


line stmt bran cond sub pod time code
1             package Archive::Lha::Stream::Hex;
2            
3 2     2   318408 use strict;
  2         5  
  2         99  
4 2     2   11 use warnings;
  2         5  
  2         151  
5 2     2   12 use Carp;
  2         3  
  2         194  
6 2     2   13 use base qw( Archive::Lha::Stream::Base );
  2         5  
  2         1128  
7            
8             sub open {
9 1     1 1 5 my ($self, %options) = @_;
10            
11 1 50       7 croak "Array reference of hex strings is missing" unless ref $options{hex} eq 'ARRAY';
12            
13 1         4 my @array = map { pack 'H2', $_ } @{ $options{hex} };
  96         206  
  1         5  
14            
15 1         11 $self->{array} = \@array;
16 1         4 $self->{length} = scalar @array;
17 1         5 $self->{pos} = 0;
18             }
19            
20             sub read {
21 5     5 1 80 my ($self, $length) = @_;
22            
23 5         9 my $from = $self->{pos};
24 5         12 my $to = $self->{pos} + $length - 1;
25 5 100       16 $to = $self->{length} - 1 if $to >= $self->{length};
26 5         34 my $str = join '', @{ $self->{array} }[$from .. $to];
  5         29  
27 5         18 $self->{pos} = $to + 1;
28 5         61 return $str;
29             }
30            
31             1;
32            
33             __END__