blib/lib/Archive/StringToZip.pm

filter: Statementstmt 100% 38 / 38 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 98.1% 53 / 54 CC 5 SCAR 10.4
CC
5
Cov
98%
zipString
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.8
↑ Summary
1 package Archive::StringToZip;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use vars qw(@ISA @EXPORT_OK $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use IO::String ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use base qw(Archive::Zip);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 require Exporter;
12 4 @ISA = qw(Exporter Archive::Zip::Archive Archive::Zip);
13 4 @EXPORT_OK = qw(zipString);
14  
15  
16 4 $VERSION = '1.03';
17  
18 8 ▶sub zipString {
Subroutine zipString: called CC=5 SCAR=16.1
Pod documented
19 8 ▶ my $self = ref($_[0]) ? shift : __PACKAGE__->new();
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 6 2 8
20 8 my ($string, $filename) = @_;
21  
22 8 ▶ croak 'Cannot archive an undefined string' unless defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 3 5 8
23 5 ▶ $filename = 'file.txt' unless $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless $filename 2 3 5
24  
25 5 my $SH = IO::String->new();
26
27 5 my $member = $self->addString($string, $filename);
28 5 $member->desiredCompressionMethod(COMPRESSION_DEFLATED);
29 5 $member->desiredCompressionLevel( 9 );
30  
31 5 my $status = $self->writeToFileHandle($SH);
32 5 ▶ die $! if $status != AZ_OK;
Branch: 1 branch
BranchTrueFalseTotal
if $status != 0 0 5 5
33  
34 5 binmode STDOUT; # necessary for Win32 and does no harm on *nix
35 5 $SH->setpos(0);
36 5 return do { local $/ = undef; $SH->getline };
37 }
38  
39 4 1;
40  
41 __END__
↑ Summary