| 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::Array; | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 40 | ▶ | use base 'PDF::API2::Basic::PDF::Objind'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 40 | our $VERSION = '2.044'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | PDF::API2::Basic::PDF::Array - Low-level PDF array object | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | =head2 PDF::Array->new($parent, @values) | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | Creates an array with the given storage parent and an optional list of values to | ||||||||||||||||||||||||||||||||||||||||||
| 27 | initialise the array with. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 1095 | ▶ | my ($class, @values) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1095 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1095 | $self->{' val'} = [@values]; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 1095 | $self->{' realised'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1095 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 1095 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | =head2 $a->outobjdeep($fh, $pdf) | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | Outputs an array as a PDF array to the given filehandle. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | sub outobjdeep { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 619 | ▶ | my ($self, $fh, $pdf) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
outobjdeep: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 619 | $fh->print('[ '); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 619 | foreach my $obj (@{$self->{' val'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 53 | 1841 | $obj->outobj($fh, $pdf); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 1841 | $fh->print(' '); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 619 | $fh->print(']'); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | =head2 $a->elements() | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | Returns the contents of the array. | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub elementsof { return elements(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
elementsof: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | sub elements { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 665 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
elements: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 665 | return @{$self->{' val'}}; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | =head2 $a->add_elements(@elements) | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | Appends the given elements to the array. An element is only added if it | ||||||||||||||||||||||||||||||||||||||||||
| 75 | is defined. | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | sub add_elements { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 27380 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_elements: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 27380 | foreach my $element (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 83 | 27382 | ▶ | next unless defined $element; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 27382 | push @{$self->{' val'}}, $element; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 27380 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | =head2 $a->remove_element($element) | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | Removes all occurrences of an element from an array. | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub removeobj { return remove_element(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
removeobj: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | sub remove_element { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my ($self, $element) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove_element: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $self->{' val'} = [ grep { $_ ne $element } @{$self->{' val'}} ]; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =head2 $a->val() | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | Returns a reference to the contents of the array. | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | sub val { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | ▶ | return $_[0]->{' val'}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
val: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | =head2 $a->copy($pdf) | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | Copies the array with deep-copy on elements which are not full PDF objects | ||||||||||||||||||||||||||||||||||||||||||
| 117 | with respect to a particular $pdf output context | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | sub copy { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 144 | ▶ | my ($self, $pdf) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy: called CC=5 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 144 | my $res = $self->SUPER::copy($pdf); | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 144 | $res->{' val'} = []; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 144 | foreach my $e (@{$self->{' val'}}) { | |||||||||||||||||||||||||||||||||||||||||
| 127 | 718 | ▶ | if (ref($e) and $e->can('is_obj') and not $e->is_obj($pdf)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $e and $e->can("is_obj") and not $e->is_obj($pdf)
ref $e and $e->can("is_obj")
MC/DC0%0/3
ref $e and $e->can("is_obj") and not $e->is_obj($pdf)
ref $e
$e->can("is_obj")
not $e->is_obj($pdf)
Truth table25%1/4
A and B and not(C)
A= ref $eB= $e->can("is_obj")C= not $e->is_obj($pdf)
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 718 | push(@{$res->{' val'}}, $e->copy($pdf)); | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | push(@{$res->{' val'}}, $e); | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 144 | return $res; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||