line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#======================================================================= |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# THIS IS A REUSED PERL MODULE, FOR PROPER LICENCING TERMS SEE BELOW: |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Copyright Martin Hosken |
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::Array; |
17
|
|
|
|
|
|
|
|
18
|
37
|
|
|
37
|
|
279
|
use base 'PDF::Builder::Basic::PDF::Objind'; |
|
37
|
|
|
|
|
82
|
|
|
37
|
|
|
|
|
18749
|
|
19
|
|
|
|
|
|
|
|
20
|
37
|
|
|
37
|
|
274
|
use strict; |
|
37
|
|
|
|
|
80
|
|
|
37
|
|
|
|
|
751
|
|
21
|
37
|
|
|
37
|
|
178
|
use warnings; |
|
37
|
|
|
|
|
75
|
|
|
37
|
|
|
|
|
20734
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '3.023'; # VERSION |
24
|
|
|
|
|
|
|
our $LAST_UPDATE = '3.022'; # manually update whenever code is changed |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 NAME |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
PDF::Builder::Basic::PDF::Array - Corresponds to a PDF array. |
29
|
|
|
|
|
|
|
Inherits from L |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 METHODS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 PDF::Array->new($parent, @values) |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Creates an array with the given storage parent and an optional list of values to |
36
|
|
|
|
|
|
|
initialise the array with. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new { |
41
|
1243
|
|
|
1243
|
1
|
2767
|
my ($class, @values) = @_; |
42
|
1243
|
|
|
|
|
2207
|
my $self = {}; |
43
|
|
|
|
|
|
|
|
44
|
1243
|
|
|
|
|
3389
|
$self->{' val'} = [@values]; |
45
|
1243
|
|
|
|
|
2344
|
$self->{' realised'} = 1; |
46
|
1243
|
|
|
|
|
2113
|
bless $self, $class; |
47
|
1243
|
|
|
|
|
4202
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 $a->outobjdeep($fh, $pdf) |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Outputs an array as a PDF array to the given filehandle. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub outobjdeep { |
57
|
689
|
|
|
689
|
1
|
1214
|
my ($self, $fh, $pdf) = @_; |
58
|
|
|
|
|
|
|
|
59
|
689
|
|
|
|
|
1694
|
$fh->print('[ '); |
60
|
689
|
|
|
|
|
3593
|
foreach my $obj (@{$self->{' val'}}) { |
|
689
|
|
|
|
|
1533
|
|
61
|
10248
|
|
|
|
|
60809
|
$obj->outobj($fh, $pdf); |
62
|
10248
|
|
|
|
|
18056
|
$fh->print(' '); |
63
|
|
|
|
|
|
|
} |
64
|
689
|
|
|
|
|
4382
|
$fh->print(']'); |
65
|
689
|
|
|
|
|
3640
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 $a->elements() |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Returns the contents of the array. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Formerly called C, which is now B. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
1
|
0
|
8
|
sub elementsof { return elements(@_); } |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub elements { |
79
|
901
|
|
|
901
|
1
|
1461
|
my $self = shift(); |
80
|
901
|
|
|
|
|
1424
|
return @{$self->{' val'}}; |
|
901
|
|
|
|
|
2914
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 $a->add_elements(@elements) |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Appends the given elements to the array. An element is only added if it |
86
|
|
|
|
|
|
|
is defined. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub add_elements { |
91
|
27866
|
|
|
27866
|
1
|
38920
|
my $self = shift(); |
92
|
|
|
|
|
|
|
|
93
|
27866
|
|
|
|
|
42327
|
foreach my $element (@_) { |
94
|
27868
|
50
|
|
|
|
49227
|
next unless defined $element; |
95
|
27868
|
|
|
|
|
35437
|
push @{$self->{' val'}}, $element; |
|
27868
|
|
|
|
|
56133
|
|
96
|
|
|
|
|
|
|
} |
97
|
27866
|
|
|
|
|
52519
|
return $self; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 $a->remove_element($element) |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Removes all occurrences of an element from an array. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Formerly called C, which is now B and will be removed. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# not listed as deprecated, not used internally, should not have been |
109
|
|
|
|
|
|
|
# used in external code. remove after July 2021. |
110
|
0
|
|
|
0
|
0
|
0
|
sub removeobj { return remove_element(@_); } |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub remove_element { |
113
|
0
|
|
|
0
|
1
|
0
|
my ($self, $element) = @_; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
0
|
$self->{' val'} = [ grep { $_ ne $element } @{$self->{' val'}} ]; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
116
|
0
|
|
|
|
|
0
|
return $self; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 $a->val() |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Returns a reference to the contents of the array. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub val { |
126
|
4
|
|
|
4
|
1
|
15
|
return $_[0]->{' val'}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 $a->copy($pdf) |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Copies the array with deep-copy on elements which are not full PDF objects |
132
|
|
|
|
|
|
|
with respect to a particular $pdf output context. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub copy { |
137
|
151
|
|
|
151
|
1
|
366
|
my ($self, $pdf) = @_; |
138
|
|
|
|
|
|
|
|
139
|
151
|
|
|
|
|
540
|
my $res = $self->SUPER::copy($pdf); |
140
|
|
|
|
|
|
|
|
141
|
151
|
|
|
|
|
325
|
$res->{' val'} = []; |
142
|
151
|
|
|
|
|
284
|
foreach my $e (@{$self->{' val'}}) { |
|
151
|
|
|
|
|
396
|
|
143
|
1944
|
50
|
33
|
|
|
8012
|
if (ref($e) and $e->can('is_obj') and not $e->is_obj($pdf)) { |
|
|
|
33
|
|
|
|
|
144
|
1944
|
|
|
|
|
2367
|
push @{$res->{' val'}}, $e->copy($pdf); |
|
1944
|
|
|
|
|
3741
|
|
145
|
|
|
|
|
|
|
} else { |
146
|
0
|
|
|
|
|
0
|
push @{$res->{' val'}}, $e; |
|
0
|
|
|
|
|
0
|
|
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
151
|
|
|
|
|
524
|
return $res; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |