lib/PDF/Imposition/Schema1x1.pm

filter: Statementstmt 97.8% 45 / 46 Branchbran 81.2% 13 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 89.3% 67 / 75 CC 11 SCAR 17.4
CC
11
Cov
91%
_do_impose
9.0
cropmarks_options
3.4
BEGIN
1.0
CRAP 5.7
« lib/PDF/Imposition/Schema1x8x2.pm ↑ Summary lib/PDF/Imposition/Schema1repeat4.pm »
1 package PDF::Imposition::Schema1x1;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use Types::Standard qw/Bool/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 with "PDF::Imposition::Schema";
11  
12  
13 =head1 NAME
14  
15 PDF::Imposition::Schema1x1 - 1:1 Imposition schema
16  
17 =head2 SYNOPSIS
18  
19 use PDF::Imposition::Schema1x1;
20 my $imposer = PDF::Imposition::Schema2up->new(
21 signature => "10-20",
22 file => "test.pdf",
23 output => "out.pdf",
24 cover => 1,
25 pages_per_sheet => 4,
26 );
27 $imposer->impose;
28  
29 The output pdf will be in C<$imposer->output>
30  
31 =head1 SCHEMA EXPLANATION
32  
33 This is a 1:1 imposition schema, meaning that apparently doesn't do anything.
34  
35 The purpose of this module is to do 2 things:
36  
37 =over 4
38  
39 =item Convert the PDF to version 1.4, if not already so.
40  
41 =item Handle the signature rounding and optimization
42  
43 This for example means that a pdf with 6 pages will end up with 8
44 pages (6 + 2 empty), and if you pass the C<cover> option with a true
45 value, you'll get the sixth page as page 8.
46  
47 Also you can get the computed value calling C<computed_signature> and
48 the total output pages with C<total_output_pages>.
49  
50 =back
51  
52 If you don't need any of this, you don't have any reason to use this
53 module.
54  
55 =head2 cover
56  
57 This schema supports the cover option.
58  
59 =cut
60  
61 3 has cover => (is => 'rw', isa => Bool);
62  
63 7 ▶sub _do_impose {
Subroutine _do_impose: called CC=9 SCAR=22.0
64 7 my $self = shift;
65 7 $self->out_pdf_obj->mediabox(
66 $self->orig_width,
67 $self->orig_height,
68 );
69 7 my $total_pages = $self->total_pages;
70 7 my $signature = $self->computed_signature;
71 7 my $max_page = $self->total_output_pages;
72 7 my $needed = $max_page - $total_pages;
73 7 ▶ die "negative number of needed pages, this is a bug" if $needed < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $needed < 0 0 7 7
74 7 my @sequence = (1 .. $total_pages);
75 7 ▶ if ($needed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($needed) 6 1 7
76 6 my $last;
77 6 ▶ if ($self->cover) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cover) 5 1 6
78 5 $last = pop @sequence;
79 }
80 6 ▶ while ($needed > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($needed > 0) 18 6 24
81 18 push @sequence, undef;
82 18 $needed--;
83 }
84 6 ▶ push @sequence, $last if $last;
Branch: 1 branch
BranchTrueFalseTotal
if $last 5 1 6
85 }
86 7 ▶ die "Something went off" if @sequence != $max_page;
Branch: 1 branch
BranchTrueFalseTotal
if @sequence != $max_page 0 7 7
87 7 foreach my $pageno (@sequence) {
88 68 my $page = $self->out_pdf_obj->page;
89 68 my $gfx = $page->gfx;
90 68 ▶ if (my $chunk = $self->get_imported_page($pageno)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $chunk = $self->get_imported_page($pageno)) 50 18 68
91 50 $gfx->formimage($chunk, 0, 0);
92 }
93 }
94 }
95  
96 =head1 INTERNALS
97  
98 =head2 cropmarks_options
99  
100 Disable signature.
101  
102 =cut
103  
104 2 ▶sub cropmarks_options {
Subroutine cropmarks_options: called CC=3 SCAR=12.3
Pod documented
105 2 my $self = shift;
106 2 my %options = (
107 top => 1,
108 bottom => 1,
109 inner => 1,
110 outer => 1,
111 # no shifting need
112 twoside => 0,
113 );
114 2 ▶ if ($self->signature and $self->pages_per_sheet > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->signature and $self->pages_per_sheet > 1) { } 0 2 2
Condition33%1/3
$self->signature and $self->pages_per_sheet > 1
!ll&&!rl&&r
020
MC/DC0%0/2
$self->signature and $self->pages_per_sheet > 1
$self->signature $self->pages_per_sheet > 1
Truth table33%1/3
A and B
A= $self->signatureB= $self->pages_per_sheet > 1
ABresult
0X0
100
111
115 0 $options{signature} = $self->computed_signature;
116 }
117 else {
118 2 $options{signature} = 0;
119 }
120  
121 2 return %options;
122 }
123  
124 3 1;
« lib/PDF/Imposition/Schema1x8x2.pm ↑ Summary lib/PDF/Imposition/Schema1repeat4.pm »