File Coverage

blib/lib/PDF/API2/Basic/PDF/Filter.pm
Criterion Covered Total %
statement 28 41 68.2
branch 0 8 0.0
condition 0 6 0.0
subroutine 9 10 90.0
pod 1 2 50.0
total 38 67 56.7


line stmt bran cond sub pod time code
1             # Code in the PDF::API2::Basic::PDF namespace was originally copied from the
2             # Text::PDF distribution.
3             #
4             # Copyright Martin Hosken
5             #
6             # Martin Hosken's code may be used under the terms of the MIT license.
7             # Subsequent versions of the code have the same license as PDF::API2.
8              
9             package PDF::API2::Basic::PDF::Filter;
10              
11 43     43   325 use strict;
  43         96  
  43         1379  
12 43     43   239 use warnings;
  43         96  
  43         2047  
13              
14             our $VERSION = '2.043'; # VERSION
15              
16 43     43   19797 use PDF::API2::Basic::PDF::Filter::ASCII85Decode;
  43         134  
  43         1579  
17 43     43   20107 use PDF::API2::Basic::PDF::Filter::ASCIIHexDecode;
  43         113  
  43         1509  
18 43     43   20011 use PDF::API2::Basic::PDF::Filter::FlateDecode;
  43         164  
  43         2211  
19 43     43   25234 use PDF::API2::Basic::PDF::Filter::LZWDecode;
  43         144  
  43         1676  
20 43     43   19404 use PDF::API2::Basic::PDF::Filter::RunLengthDecode;
  43         122  
  43         1770  
21 43     43   328 use Scalar::Util qw(blessed reftype);
  43         101  
  43         12659  
22              
23             =head1 NAME
24              
25             PDF::API2::Basic::PDF::Filter - Abstract superclass for PDF stream filters
26              
27             =head1 SYNOPSIS
28              
29             $f = PDF::API2::Basic::PDF::Filter->new;
30             $str = $f->outfilt($str, 1);
31             print OUTFILE $str;
32              
33             while (read(INFILE, $dat, 4096))
34             { $store .= $f->infilt($dat, 0); }
35             $store .= $f->infilt("", 1);
36              
37             =head1 DESCRIPTION
38              
39             A Filter object contains state information for the process of outputting
40             and inputting data through the filter. The precise state information stored
41             is up to the particular filter and may range from nothing to whole objects
42             created and destroyed.
43              
44             Each filter stores different state information for input and output and thus
45             may handle one input filtering process and one output filtering process at
46             the same time.
47              
48             =head1 METHODS
49              
50             =head2 PDF::API2::Basic::PDF::Filter->new
51              
52             Creates a new filter object with empty state information ready for processing
53             data both input and output.
54              
55             =head2 $dat = $f->infilt($str, $isend)
56              
57             Filters from output to input the data. Notice that $isend == 0 implies that there
58             is more data to come and so following it $f may contain state information
59             (usually due to the break-off point of $str not being tidy). Subsequent calls
60             will incorporate this stored state information.
61              
62             $isend == 1 implies that there is no more data to follow. The
63             final state of $f will be that the state information is empty. Error messages
64             are most likely to occur here since if there is required state information to
65             be stored following this data, then that would imply an error in the data.
66              
67             =head2 $str = $f->outfilt($dat, $isend)
68              
69             Filter stored data ready for output. Parallels C.
70              
71             =cut
72              
73             sub new {
74 6     6 1 111 my $class = shift();
75 6         16 my $self = {};
76              
77 6         14 bless $self, $class;
78              
79 6         19 return $self;
80             }
81              
82             sub release {
83 0     0 0   my $self = shift();
84 0 0         return $self unless ref($self);
85              
86             # delete stuff that we know we can, here
87 0           my @tofree = map { delete $self->{$_} } keys %$self;
  0            
88              
89 0           while (my $item = shift @tofree) {
90 0           my $ref = ref($item);
91 0 0 0       if (blessed($item) and $item->can('release')) {
    0 0        
    0          
92 0           $item->release();
93             }
94             elsif ($ref eq 'ARRAY') {
95 0           push @tofree, @$item;
96             }
97             elsif (defined(reftype($ref)) and reftype($ref) eq 'HASH') {
98 0           release($item);
99             }
100             }
101              
102             # check that everything has gone
103 0           foreach my $key (keys %$self) {
104             # warn ref($self) . " still has '$key' key left after release.\n";
105 0           $self->{$key} = undef;
106 0           delete $self->{$key};
107             }
108             }
109              
110             1;