File Coverage

blib/lib/SWF/BinStream/Codec/Zlib.pm
Criterion Covered Total %
statement 34 37 91.8
branch 6 14 42.8
condition n/a
subroutine 10 11 90.9
pod n/a
total 50 62 80.6


line stmt bran cond sub pod time code
1             package SWF::BinStream::Codec::Zlib;
2              
3 1     1   7 use strict;
  1         2  
  1         87  
4              
5             $SWF::BinStream::Codec::Zlib::VERSION = "0.01";
6              
7             package SWF::BinStream::Codec::Zlib::Read;
8              
9 1     1   4059 use Compress::Zlib;
  1         122688  
  1         366  
10 1     1   9 use Carp;
  1         3  
  1         193  
11              
12             sub new {
13 1 50   1   6 my $z = inflateInit() or croak "Can't create zlib stream";
14 1         242 bless \$z, shift;
15             }
16              
17              
18             sub decode {
19 2     2   21 my ($self, $data) = @_;
20              
21 2         12 my ($out, $status) = $$self->inflate(\$data);
22 2 50       82 defined $out or croak "Zlib raised an error $status";
23 2         11 $out;
24             }
25              
26 0     0   0 sub close {
27             }
28              
29             package SWF::BinStream::Codec::Zlib::Write;
30              
31 1     1   7 use Compress::Zlib;
  1         1  
  1         446  
32 1     1   7 use Carp;
  1         1  
  1         311  
33              
34             sub new {
35 1 50   1   6 my $z = deflateInit() or croak "Can't create zlib stream ";
36 1         16552 bless \$z, shift;
37             }
38              
39              
40             sub encode {
41 4     4   915 my ($self, $data) = @_;
42              
43 4         22 my ($out, $status) = $$self->deflate(\$data);
44 4 50       74 defined $out or croak "Zlib raised an error $status (wm)";
45 4         17 $out;
46             }
47              
48             sub close {
49 1     1   4 my ($self, $data) = @_;
50 1         2 my $z = $$self;
51 1         2 my ($out, $out1, $status);
52              
53 1 50       5 if ($data ne '') {
54 0         0 ($out, $status) = $z->deflate(\$data);
55 0 0       0 defined $out or croak "Zlib raised an error $status (wc1)";
56             }
57 1         7 ($out1, $status) = $z->flush;
58 1 50       138 defined $out1 or croak "Zlib raised an error $status (wc2)";
59 1         1123 $out .= $out1;
60             }
61              
62             1;
63             __END__