Builder/Resource/XObject/Form.pm

filter: Statementstmt 68.4% 26 / 38 Branchbran 20.0% 2 / 10 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 85.7% 6 / 7 Podpod 100% 3 / 3 totaltotal 48.6% 37 / 76 CC 10 SCAR 39.4
CC
10
Cov
47%
resource
90.0
bbox
2.0
BEGIN
1.0
CRAP 51.2
« Builder/Resource/Font.pm ↑ Summary Builder/Resource/UniFont.pm »
1 package PDF::Builder::Resource::XObject::Form;
2  
3 39 ▶use base 'PDF::Builder::Resource::XObject';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 39 our $VERSION = '3.028'; # VERSION
9 39 our $LAST_UPDATE = '3.027'; # manually update whenever code is changed
10  
11 39 ▶use PDF::Builder::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 PDF::Builder::Resource::XObject::Form - Base class for external form objects
16  
17 Inherits from L<PDF::Builder::Resource::XObject>
18  
19 =head1 METHODS
20  
21 =head2 new
22  
23 $form = PDF::Builder::Resource::XObject::Form->new($pdf)
24  
25 =over
26  
27 Creates a form resource.
28  
29 =back
30  
31 =cut
32  
33 10 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
34 10 my ($class, $pdf, $name) = @_;
35  
36 10 my $self = $class->SUPER::new($pdf, $name);
37  
38 10 $self->subtype('Form');
39 10 $self->{'FormType'} = PDFNum(1);
40  
41 10 return $self;
42 }
43  
44 =head2 bbox
45  
46 ($llx, $lly, $urx, $ury) = $form->bbox($llx, $lly, $urx, $ury)
47  
48 =over
49  
50 Get or set the coordinates of the form object's bounding box.
51  
52 =back
53  
54 =cut
55  
56 11 ▶sub bbox {
Subroutine bbox: called CC=2 SCAR=6.9
Pod documented
57 11 my $self = shift();
58  
59 11 ▶ if (scalar @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 10 1 11
60 10 $self->{'BBox'} = PDFArray(map { PDFNum($_) } @_);
61 }
62  
63 11 return map { $_->val() } $self->{'BBox'}->elements();
64 }
65  
66 =head2 resource
67  
68 $resource = $form->resource($type, $key)
69  
70 $form->resource($type, $key, $object, $force)
71  
72 =over
73  
74 Get or add a resource required by the form's contents, such as a Font, XObject, ColorSpace, etc.
75  
76 By default, an existing C<$key> will not be overwritten. Set C<$force> to override this behavior.
77  
78 =back
79  
80 =cut
81  
82 0 ▶sub resource {
Subroutine resource: not called CC=9 SCAR=45.0
Pod documented
83 0 my ($self, $type, $key, $object, $force) = @_;
84 # we are a self-contained content stream.
85  
86 0 ▶ $self->{'Resources'} ||= PDFDict();
Condition0%0/3
$self->{"Resources"} ||= PDFDict()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"Resources"} ||= PDFDict()
$self->{"Resources"} PDFDict()
Truth table0%0/3
A ||= B
A= $self->{"Resources"}B= PDFDict()
ABresult
1X1
011
000
87  
88 0 my $dict = $self->{'Resources'};
89 0 ▶ $dict->realise() if ref($dict) =~ /Objind$/;
Branch: 1 branch
BranchTrueFalseTotal
if ref($dict) =~ /Objind$/ 0 0 0
90  
91 0 ▶ $dict->{$type} ||= PDFDict();
Condition0%0/3
$dict->{$type} ||= PDFDict()
l!l&&r!l&&!r
000
MC/DC0%0/2
$dict->{$type} ||= PDFDict()
$dict->{$type} PDFDict()
Truth table0%0/3
A ||= B
A= $dict->{$type}B= PDFDict()
ABresult
1X1
011
000
92 0 ▶ $dict->{$type}->realise() if ref($dict->{$type}) =~ /Objind$/;
Branch: 1 branch
BranchTrueFalseTotal
if ref($dict->{$type}) =~ /Objind$/ 0 0 0
93  
94 0 ▶ unless (defined $object) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $object) 0 0 0
95 0 ▶ return $dict->{$type}->{$key} || undef;
Condition0%0/2
$dict->{$type}{$key} || undef
l!l
00
MC/DC0%0/1
$dict->{$type}{$key} || undef
$dict->{$type}{$key}
Truth table0%0/2
A
A= $dict->{$type}{$key}
Aresult
11
00
96 }
97  
98 0 ▶ if ($force) {
Branch: 1 branch
BranchTrueFalseTotal
if ($force) { } 0 0 0
99 0 $dict->{$type}->{$key} = $object;
100 }
101 else {
102 0 ▶ $dict->{$type}->{$key} ||= $object;
Condition0%0/3
$dict->{$type}{$key} ||= $object
l!l&&r!l&&!r
000
MC/DC0%0/2
$dict->{$type}{$key} ||= $object
$dict->{$type}{$key} $object
Truth table0%0/3
A ||= B
A= $dict->{$type}{$key}B= $object
ABresult
1X1
011
000
103 }
104  
105 0 return $dict;
106 }
107  
108 39 1;
« Builder/Resource/Font.pm ↑ Summary Builder/Resource/UniFont.pm »