PDF/Page.pm

filter: Statementstmt 85.3% 35 / 41 Branchbran 40.0% 4 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 3 / 3 totaltotal 78.6% 48 / 61 CC 7 SCAR 12.6
CC
7
Cov
76%
ship_out
6.0
add
5.2
new
2.0
CRAP 3.5
« PDF/Name.pm ↑ Summary PDF/Bool.pm »
1 package Text::PDF::Page;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 @ISA = qw(Text::PDF::Pages);
6 # no warnings qw(uninitialized);
7 1 ▶use Text::PDF::Pages;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Text::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Text::PDF::Page - Represents a PDF page, inherits from L<Text::PDF::Pages>
14  
15 =head1 DESCRIPTION
16  
17 Represents a page of output in PDF. It also keeps track of the content stream,
18 any resources (such as fonts) being switched, etc.
19  
20 Page inherits from Pages due to a number of shared methods. They are really
21 structurally quite different.
22  
23 =head1 INSTANCE VARIABLES
24  
25 A page has various working variables:
26  
27 =over
28  
29 =item curstrm
30  
31 The currently open stream
32  
33 =back
34  
35 =head1 METHODS
36  
37 =head2 Text::PDF::Page->new($pdf, $parent, $index)
38  
39 Creates a new page based on a pages object (perhaps the root object).
40  
41 The page is also added to the parent at this point, so pages are ordered in
42 a PDF document in the order in which they are created rather than in the order
43 they are closed.
44  
45 Only the essential elements in the page dictionary are created here, all others
46 are either optional or can be inherited.
47  
48 The optional index value indicates the index in the parent list that this page
49 should be inserted (so that new pages need not be appended)
50  
51 =cut
52  
53 sub new
54 {
55 1 ▶ my ($class, $pdf, $parent, $index) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
56 1 my ($self) = {};
57  
58 1 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1 1
59 1 $self = $class->SUPER::new($pdf, $parent);
60 1 $self->{'Type'} = PDFName('Page');
61 1 delete $self->{'Count'};
62 1 delete $self->{'Kids'};
63 1 $parent->add_page($self, $index);
64 1 $self;
65 }
66  
67  
68 =head2 $p->add($str)
69  
70 Adds the string to the currently active stream for this page. If no stream
71 exists, then one is created and added to the list of streams for this page.
72  
73 The slightly cryptic name is an aim to keep it short given the number of times
74 people are likely to have to type it.
75  
76 =cut
77  
78 sub add
79 {
80 1 ▶ my ($self, $str) = @_;
Subroutine add: called CC=5 SCAR=16.5
Pod documented
81 1 my ($strm) = $self->{' curstrm'};
82  
83 1 ▶ if (!defined $strm)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $strm) 1 0 1
84 {
85 1 $strm = Text::PDF::Dict->new;
86 1 foreach (@{$self->{' outto'}})
87 1 { $_->new_obj($strm); }
88 1 ▶ $self->{'Contents'} = PDFArray() unless defined $self->{'Contents'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"Contents"} 1 0 1
89 1 ▶ unless (ref $self->{'Contents'} eq "Text::PDF::Array")
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->{"Contents"} eq "Text::PDF::Array") 0 1 1
90 0 { $self->{'Contents'} = PDFArray($self->{'Contents'}); }
91 1 $self->{'Contents'}->add_elements($strm);
92 1 $self->{' curstrm'} = $strm;
93 }
94  
95 1 $strm->{' stream'} .= $str;
96 1 $self;
97 }
98  
99  
100 =head2 $p->ship_out($pdf)
101  
102 Ships the page out to the given output file context
103  
104 =cut
105  
106 sub ship_out
107 {
108 0 ▶ my ($self, $pdf) = @_;
Subroutine ship_out: not called CC=2 SCAR=17.9
Pod documented
109  
110 0 $pdf->ship_out($self);
111 0 ▶ if (defined $self->{'Contents'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"Contents"}) 0 0 0
112 0 { $pdf->ship_out($self->{'Contents'}->elementsof); }
113 0 $self;
114 }
115  
116  
« PDF/Name.pm ↑ Summary PDF/Bool.pm »