| 1 | # Code in the PDF::API2::Basic::PDF namespace was originally copied from the | ||||||||||||||||||||||||||||||||||||
| 2 | # Text::PDF distribution. | ||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||
| 4 | # Copyright Martin Hosken <Martin_Hosken@sil.org> | ||||||||||||||||||||||||||||||||||||
| 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 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | 43 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | 43 | our $VERSION = '2.044'; # VERSION | |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||
| 16 | 43 | ▶ | use PDF::API2::Basic::PDF::Filter::ASCII85Decode; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 17 | 43 | ▶ | use PDF::API2::Basic::PDF::Filter::ASCIIHexDecode; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 18 | 43 | ▶ | use PDF::API2::Basic::PDF::Filter::FlateDecode; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 19 | 43 | ▶ | use PDF::API2::Basic::PDF::Filter::LZWDecode; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 20 | 43 | ▶ | use PDF::API2::Basic::PDF::Filter::RunLengthDecode; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 21 | 43 | ▶ | use Scalar::Util qw(blessed reftype); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 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<infilt>. | ||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||
| 73 | sub new { | ||||||||||||||||||||||||||||||||||||
| 74 | 6 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 75 | 6 | my $self = {}; | |||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||
| 77 | 6 | bless $self, $class; | |||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||
| 79 | 6 | return $self; | |||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||
| 82 | sub release { | ||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||||||||||
|
Subroutine
release: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | return $self unless ref($self); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||
| 86 | # delete stuff that we know we can, here | ||||||||||||||||||||||||||||||||||||
| 87 | 0 | my @tofree = map { delete $self->{$_} } keys %$self; | |||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | while (my $item = shift @tofree) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $ref = ref($item); | |||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if (blessed($item) and $item->can('release')) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
builtin::blessed($item) and $item->can("release")
MC/DC0%0/2
builtin::blessed($item) and $item->can("release")
builtin::blessed($item)
$item->can("release")
Truth table0%0/3
A and B
A= builtin::blessed($item)B= $item->can("release")
| |||||||||||||||||||||||||||||||||||||
| 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') { | |||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined builtin::reftype($ref) and builtin::reftype($ref) eq "HASH"
MC/DC0%0/2
defined builtin::reftype($ref) and builtin::reftype($ref) eq "HASH"
defined builtin::reftype($ref)
builtin::reftype($ref) eq "HASH"
Truth table0%0/3
A and B
A= defined builtin::reftype($ref)B= builtin::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 | 43 | 1; | |||||||||||||||||||||||||||||||||||