| 1 | #======================================================================= | ||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||
| 3 | # THIS IS A REUSED PERL MODULE, FOR PROPER LICENCING TERMS SEE BELOW: | ||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||
| 5 | # Copyright Martin Hosken <Martin_Hosken@sil.org> | ||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||
| 7 | # No warranty or expression of effectiveness, least of all regarding | ||||||||||||||||||||||||||||||||||||
| 8 | # anyone's safety, is implied in this software or documentation. | ||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||
| 10 | # This specific module is licensed under the Perl Artistic License. | ||||||||||||||||||||||||||||||||||||
| 11 | # Effective 28 January 2021, the original author and copyright holder, | ||||||||||||||||||||||||||||||||||||
| 12 | # Martin Hosken, has given permission to use and redistribute this module | ||||||||||||||||||||||||||||||||||||
| 13 | # under the MIT license. | ||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||
| 15 | #======================================================================= | ||||||||||||||||||||||||||||||||||||
| 16 | package PDF::Builder::Basic::PDF::Filter; | ||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||
| 18 | 45 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 19 | 45 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||
| 21 | 45 | our $VERSION = '3.028'; # VERSION | |||||||||||||||||||||||||||||||||||
| 22 | 45 | our $LAST_UPDATE = '3.027'; # manually update whenever code is changed | |||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||
| 24 | 45 | ▶ | use PDF::Builder::Basic::PDF::Filter::ASCII85Decode; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 25 | 45 | ▶ | use PDF::Builder::Basic::PDF::Filter::ASCIIHexDecode; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 26 | 45 | ▶ | use PDF::Builder::Basic::PDF::Filter::FlateDecode; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 27 | 45 | ▶ | use PDF::Builder::Basic::PDF::Filter::LZWDecode; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 28 | 45 | ▶ | use PDF::Builder::Basic::PDF::Filter::RunLengthDecode; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 29 | # use PDF::Builder::Basic::PDF::Filter::CCITTFaxDecode; when TIFF changes in | ||||||||||||||||||||||||||||||||||||
| 30 | 45 | ▶ | use Scalar::Util qw(blessed reftype); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||
| 32 | =head1 NAME | ||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||
| 34 | PDF::Builder::Basic::PDF::Filter - Abstract superclass for PDF stream filters | ||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||
| 36 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||
| 38 | $f = PDF::Builder::Basic::PDF::Filter->new(); | ||||||||||||||||||||||||||||||||||||
| 39 | $str = $f->outfilt($str, 1); | ||||||||||||||||||||||||||||||||||||
| 40 | print OUTFILE $str; | ||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||
| 42 | while (read(INFILE, $dat, 4096)) | ||||||||||||||||||||||||||||||||||||
| 43 | { $store .= $f->infilt($dat, 0); } | ||||||||||||||||||||||||||||||||||||
| 44 | $store .= $f->infilt("", 1); | ||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||
| 46 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||
| 48 | A Filter object contains state information for the process of outputting | ||||||||||||||||||||||||||||||||||||
| 49 | and inputting data through the filter. The precise state information stored | ||||||||||||||||||||||||||||||||||||
| 50 | is up to the particular filter and may range from nothing to whole objects | ||||||||||||||||||||||||||||||||||||
| 51 | created and destroyed. | ||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | Each filter stores different state information for input and output and thus | ||||||||||||||||||||||||||||||||||||
| 54 | may handle one input filtering process and one output filtering process at | ||||||||||||||||||||||||||||||||||||
| 55 | the same time. | ||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||
| 57 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||
| 59 | =head2 new | ||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||
| 61 | PDF::Builder::Basic::PDF::Filter->new() | ||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||
| 63 | =over | ||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||
| 65 | Creates a new filter object with empty state information ready for processing | ||||||||||||||||||||||||||||||||||||
| 66 | data both input and output. | ||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||
| 68 | =back | ||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||
| 70 | =head2 infilt | ||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||
| 72 | $dat = $f->infilt($str, $isend) | ||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||
| 74 | =over | ||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||
| 76 | Filters from output to input the data. Notice that C<$isend == 0> implies that | ||||||||||||||||||||||||||||||||||||
| 77 | there is more data to come and so following it C<$f> may contain state | ||||||||||||||||||||||||||||||||||||
| 78 | information (usually due to the break-off point of C<$str> not being tidy). | ||||||||||||||||||||||||||||||||||||
| 79 | Subsequent calls will incorporate this stored state information. | ||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||
| 81 | C<$isend == 1> implies that there is no more data to follow. The final state of | ||||||||||||||||||||||||||||||||||||
| 82 | C<$f> will be that the state information is empty. Error messages are most | ||||||||||||||||||||||||||||||||||||
| 83 | likely to occur here since if there is required state information to be stored | ||||||||||||||||||||||||||||||||||||
| 84 | following this data, then that would imply an error in the data. | ||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||
| 86 | =back | ||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||
| 88 | =head2 outfilt | ||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||
| 90 | $str = $f->outfilt($dat, $isend) | ||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||
| 92 | =over | ||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||
| 94 | Filter stored data ready for output. Parallels C<infilt>. | ||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||
| 96 | =back | ||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||
| 100 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 101 | 5 | my $class = shift(); | |||||||||||||||||||||||||||||||||||
| 102 | 5 | my $self = {}; | |||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||
| 104 | 5 | bless $self, $class; | |||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||
| 106 | 5 | return $self; | |||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub release { | ||||||||||||||||||||||||||||||||||
|
Subroutine
release: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $self = shift(); | |||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | return $self unless ref($self); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||
| 113 | # delete stuff that we know we can, here | ||||||||||||||||||||||||||||||||||||
| 114 | 0 | my @tofree = map { delete $self->{$_} } keys %$self; | |||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | while (my $item = shift @tofree) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $ref = ref($item); | |||||||||||||||||||||||||||||||||||
| 118 | 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")
| |||||||||||||||||||||||||||||||||||||
| 119 | 0 | $item->release(); | |||||||||||||||||||||||||||||||||||
| 120 | } elsif ($ref eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||
| 121 | 0 | push @tofree, @$item ; | |||||||||||||||||||||||||||||||||||
| 122 | ▶ | } 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"
| |||||||||||||||||||||||||||||||||||||
| 123 | 0 | release($item); | |||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||
| 127 | # check that everything has gone | ||||||||||||||||||||||||||||||||||||
| 128 | 0 | foreach my $key (keys %$self) { | |||||||||||||||||||||||||||||||||||
| 129 | # warn ref($self) . " still has '$key' key left after release.\n"; | ||||||||||||||||||||||||||||||||||||
| 130 | 0 | $self->{$key} = undef; | |||||||||||||||||||||||||||||||||||
| 131 | 0 | delete $self->{$key}; | |||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||
| 133 | 0 | return; | |||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||
| 136 | 45 | 1; | |||||||||||||||||||||||||||||||||||