File Coverage

blib/lib/Archive/Zip/StringMember.pm
Criterion Covered Total %
statement 30 35 85.7
branch 4 8 50.0
condition n/a
subroutine 7 8 87.5
pod 1 1 100.0
total 42 52 80.8


line stmt bran cond sub pod time code
1             package Archive::Zip::StringMember;
2              
3 6     6   81 use strict;
  6         55  
  6         93  
4 6     6   88 use vars qw( $VERSION @ISA );
  6         96  
  6         140  
5              
6             BEGIN {
7 6     6   112     $VERSION = '1.18';
8 6         81     @ISA = qw( Archive::Zip::Member );
9             }
10              
11 6         144 use Archive::Zip qw(
12             :CONSTANTS
13             :ERROR_CODES
14 6     6   91 );
  6         56  
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 4     4   68     my $class = shift;
20 4         75     my $string = shift;
21 4         77     my $name = shift;
22 4         120     my $self = $class->new(@_);
23 4         100     $self->contents($string);
24 4 50       111     $self->fileName($name) if defined($name);
25              
26             # Set the file date to now
27 4         210     $self->setLastModFileDateTimeFromUnix( time() );
28 4         60     $self->unixFileAttributes( $self->DEFAULT_FILE_PERMISSIONS );
29 4         48     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 38     38 1 517     my $self = shift;
44 38         399     my $string = shift;
45 38 100       586     if ( defined($string) ) {
46 7 50       155         $self->{'contents'} =
47                       pack( 'C0a*', ( ref($string) eq 'SCALAR' ) ? $$string : $string );
48 7         94         $self->{'uncompressedSize'} = $self->{'compressedSize'} =
49                       length( $self->{'contents'} );
50 7         66         $self->{'compressionMethod'} = COMPRESSION_STORED;
51                 }
52 38         726     return $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 29     29   273     my ( $self, $dataRef, $chunkSize ) = @_;
60 29         346     $$dataRef = substr( $self->contents(), $self->_readOffset(), $chunkSize );
61 29         432     return ( length($$dataRef), AZ_OK );
62             }
63              
64             1;
65