File Coverage

blib/lib/Archive/Zip/StringMember.pm
Criterion Covered Total %
statement 30 35 85.7
branch 7 10 70.0
condition n/a
subroutine 7 8 87.5
pod 1 1 100.0
total 45 54 83.3


line stmt bran cond sub pod time code
1             package Archive::Zip::StringMember;
2              
3 28     28   185 use strict;
  28         56  
  28         880  
4 28     28   137 use vars qw( $VERSION @ISA );
  28         48  
  28         1539  
5              
6             BEGIN {
7 28     28   85 $VERSION = '1.68';
8 28         1089 @ISA = qw( Archive::Zip::Member );
9             }
10              
11 28         11810 use Archive::Zip qw(
12             :CONSTANTS
13             :ERROR_CODES
14 28     28   169 );
  28         48  
15              
16             # Create a new string member. Default is COMPRESSION_STORED.
17             # Can take a ref to a string as well.
18             sub _newFromString {
19 15     15   41 my $class = shift;
20 15         38 my $string = shift;
21 15         36 my $name = shift;
22 15         125 my $self = $class->new(@_);
23 15         79 $self->contents($string);
24 15 100       94 $self->fileName($name) if defined($name);
25              
26             # Set the file date to now
27 15         96 $self->setLastModFileDateTimeFromUnix(time());
28 15         87 $self->unixFileAttributes($self->DEFAULT_FILE_PERMISSIONS);
29 15         40 return $self;
30             }
31              
32             sub _become {
33 0     0   0 my $self = shift;
34 0         0 my $newClass = shift;
35 0 0       0 return $self if ref($self) eq $newClass;
36 0         0 delete($self->{'contents'});
37 0         0 return $self->SUPER::_become($newClass);
38             }
39              
40             # Get or set my contents. Note that we do not call the superclass
41             # version of this, because it calls us.
42             sub contents {
43 166     166 1 9149 my $self = shift;
44 166         265 my $string = shift;
45 166 100       371 if (defined($string)) {
46 24 50       287 $self->{'contents'} =
47             pack('C0a*', (ref($string) eq 'SCALAR') ? $$string : $string);
48             $self->{'uncompressedSize'} = $self->{'compressedSize'} =
49 24         89 length($self->{'contents'});
50 24         46 $self->{'compressionMethod'} = COMPRESSION_STORED;
51             }
52 166 100       750 return wantarray ? ($self->{'contents'}, AZ_OK) : $self->{'contents'};
53             }
54              
55             # Return bytes read. Note that first parameter is a ref to a buffer.
56             # my $data;
57             # my ( $bytesRead, $status) = $self->readRawChunk( \$data, $chunkSize );
58             sub _readRawChunk {
59 136     136   334 my ($self, $dataRef, $chunkSize) = @_;
60 136         319 $$dataRef = substr($self->contents(), $self->_readOffset(), $chunkSize);
61 136         447 return (length($$dataRef), AZ_OK);
62             }
63              
64             1;