API3/Compat/API2/Basic/PDF/Array.pm

filter: Statementstmt 23.7% 14 / 59 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 4 / 12 Podpod 87.5% 7 / 8 totaltotal 27.7% 25 / 90 CC 9 SCAR 20.9
CC
9
Cov
21%
copy
20.0
add_elements
12.0
outobjdeep
6.0
CRAP 8.1
« API3/Compat/API2/Basic/TTF/Fdsc.pm ↑ Summary API3/Compat/API2/Resource/ColorSpace.pm »
1 #=======================================================================
2 # ____ ____ _____ _ ____ ___ ____
3 # | _ \| _ \| ___| _ _ / \ | _ \_ _| |___ \
4 # | |_) | | | | |_ (_) (_) / _ \ | |_) | | __) |
5 # | __/| |_| | _| _ _ / ___ \| __/| | / __/
6 # |_| |____/|_| (_) (_) /_/ \_\_| |___| |_____|
7 #
8 # A Perl Module Chain to faciliate the Creation and Modification
9 # of High-Quality "Portable Document Format (PDF)" Files.
10 #
11 #=======================================================================
12 #
13 # THIS IS A REUSED PERL MODULE, FOR PROPER LICENCING TERMS SEE BELOW:
14 #
15 #
16 # Copyright Martin Hosken <Martin_Hosken@sil.org>
17 #
18 # No warranty or expression of effectiveness, least of all regarding
19 # anyone's safety, is implied in this software or documentation.
20 #
21 # This specific module is licensed under the Perl Artistic License.
22 #
23 #
24 # $Id: Array.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $
25 #
26 #=======================================================================
27 package PDF::API3::Compat::API2::Basic::PDF::Array;
28
29 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
31
32 1 ▶use PDF::API3::Compat::API2::Basic::PDF::Objind;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 @ISA = qw(PDF::API3::Compat::API2::Basic::PDF::Objind);
34
35 1 ▶no warnings qw[ deprecated recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
36
37 =head1 NAME
38
39 PDF::API3::Compat::API2::Basic::PDF::Array - Corresponds to a PDF array. Inherits from L<PDF::Objind>
40
41 =head1 INSTANCE VARIABLES
42
43 This object is not an array but an associative array containing the array of
44 elements. Thus, there are special instance variables for an array object, beginning
45 with a space
46
47 =item var
48
49 Contains the actual array of elements
50
51 =head1 METHODS
52
53 =head2 PDF::Array->new($parent, @vals)
54
55 Creates an array with the given storage parent and an optional list of values to
56 initialise the array with.
57
58 =cut
59
60 sub new
61 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
62 0 my ($class, @vals) = @_;
63 0 my ($self);
64
65 0 $self->{' val'} = [@vals];
66 0 $self->{' realised'} = 1;
67 0 bless $self, $class;
68 }
69
70
71 =head2 $a->outobjdeep($fh, $pdf)
72
73 Outputs an array as a PDF array to the given filehandle.
74
75 =cut
76
77 sub outobjdeep
78 0 ▶{
Subroutine outobjdeep: not called CC=2 SCAR=17.9
Pod documented
79 0 my ($self, $fh, $pdf, %opts) = @_;
80 0 my ($obj);
81
82 0 $fh->print("[ ");
83 0 foreach $obj (@{$self->{' val'}})
84 {
85 0 $obj->outobj($fh, $pdf);
86 0 $fh->print(" ");
87 }
88 0 $fh->print("]");
89 }
90
91 sub outxmldeep
92 0 ▶{
Subroutine outxmldeep: not called CC=2 SCAR=17.9
Pod undocumented
93 0 my ($self, $fh, $pdf, %opts) = @_;
94 0 my ($obj);
95
96 0 $opts{-xmlfh}->print("<Array>\n");
97 0 foreach $obj (@{$self->{' val'}})
98 {
99 0 $obj->outxml($fh, $pdf, %opts);
100 }
101 0 $opts{-xmlfh}->print("</Array>\n");
102
103 }
104
105 =head2 $a->removeobj($elem)
106
107 Removes all occurrences of an element from an array.
108
109 =cut
110
111 sub removeobj
112 0 ▶{
Subroutine removeobj: not called CC=1 SCAR=6.9
Pod documented
113 0 my ($self, $elem) = @_;
114
115 0 $self->{' val'} = [grep($_ ne $elem, @{$self->{' val'}})];
116 }
117
118
119 =head2 $a->elementsof
120
121 Returns a list of all the elements in the array. Notice that this is
122 not the array itself but the elements in the array.
123
124 =cut
125
126 sub elementsof
127 0 ▶{ wantarray ? @{$_[0]->{' val'}} : scalar @{$_[0]->{' val'}}; }
Subroutine elementsof: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
128
129
130 =head2 $a->add_elements
131
132 Appends the given elements to the array. An element is only added if it
133 is defined.
134
135 =cut
136
137 sub add_elements
138 0 ▶{
Subroutine add_elements: not called CC=3 SCAR=24.8
Pod documented
139 0 my ($self) = shift;
140 0 my ($e);
141
142 0 foreach $e (@_)
143 0 ▶ { push (@{$self->{' val'}}, $e) if defined $e; }
Branch: 1 branch
BranchTrueFalseTotal
if defined $e 0 0 0
144 0 $self;
145 }
146
147
148 =head2 $a->val
149
150 Returns the value of the array, this is a reference to the actual array
151 containing the elements.
152
153 =cut
154
155 sub val
156 0 ▶{ $_[0]->{' val'}; }
Subroutine val: not called CC=1 SCAR=6.9
Pod documented
157
158
159 =head2 $a->copy($pdf)
160
161 Copies the array with deep-copy on elements which are not full PDF objects
162 with respect to a particular $pdf output context
163
164 =cut
165
166 sub copy
167 0 ▶{
Subroutine copy: not called CC=4 SCAR=30.0
Pod documented
168 0 my ($self, $pdf) = @_;
169 0 my ($res) = $self->SUPER::copy($pdf);
170 0 my ($e);
171
172 0 $res->{' val'} = [];
173 0 foreach $e (@{$self->{' val'}})
174 {
175 0 ▶ if (UNIVERSAL::can($e, "is_obj") && !$e->is_obj($pdf))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::can($e, 'is_obj') and not $e->is_obj($pdf)) { } 0 0 0
Condition0%0/3
UNIVERSAL::can($e, "is_obj") and not $e->is_obj($pdf)
!ll&&!rl&&r
000
MC/DC0%0/2
UNIVERSAL::can($e, "is_obj") and not $e->is_obj($pdf)
UNIVERSAL::can($e, "is_obj") not $e->is_obj($pdf)
Truth table0%0/3
A and not(B)
A= UNIVERSAL::can($e, "is_obj")B= not $e->is_obj($pdf)
ABresult
0X0
100
111
176 0 { push(@{$res->{' val'}}, $e->copy($pdf)); }
177 else
178 0 { push(@{$res->{' val'}}, $e); }
179 }
180 0 $res;
181 }
182
183 1 1;
184
185
« API3/Compat/API2/Basic/TTF/Fdsc.pm ↑ Summary API3/Compat/API2/Resource/ColorSpace.pm »