blib/lib/PDF/Report/Table.pm

filter: Statementstmt 43.7% 14 / 32 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 37.0% 20 / 54 CC 6 SCAR 31.6
CC
6
Cov
33%
addTable
42.0
new
2.0
BEGIN
1.0
CRAP 23.5
↑ Summary
1 package PDF::Report::Table;
2  
3 =head1 NAME
4  
5 PDF::Report::Table - Adds table support to PDF::Report
6  
7 =head1 SYNOPSIS
8
9 use PDF::Report;
10 use PDF::Report::Table;
11  
12 my $pdf = new PDF::Report(
13 'PageSize' => 'letter',
14 'PageOrientation' => 'Portrait',
15 );
16  
17 my $table_writer = PDF::Report::Table->new($pdf);
18
19 my $some_data =[
20 ["test1", "test2", "test3"],
21 ["test4", "test5", "test6"],
22 ["test7", "test8", "test9"],
23 ];
24
25 $table_writer->addTable($some_data);
26  
27 =head1 DESCRIPTION
28  
29 Add tables to PDF::Report.
30
31 =cut
32  
33 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 1 ▶use PDF::Report;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use PDF::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 1 our $VERSION = '1.01';
40  
41  
42 =item $new($pdf);
43  
44 my $pdf = new PDF::Report(
45 'PageSize' => 'letter',
46 'PageOrientation' => 'Portrait',
47 );
48
49 my $table_writer = PDF::Report::Table->new($pdf);
50  
51 =cut
52  
53 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
54 0 my $class = shift;
55 0 my $report = shift;
56
57 0 my $self = {};
58 0 bless $self, $class;
59  
60 0 $self->{report} = $report;
61
62 0 return $self;
63 }
64  
65 =item $table_writer->addTable(@data);
66  
67 $table_writer->addTable(
68 $some_data, # 2d array
69 $width, # default is none
70 $padding, # default is 5
71 $bgcolor_odd, # default is '#FFFFFF'
72 $bgcolor_even, # default is '#FFFFCC'
73 );
74  
75 =cut
76  
77 0 ▶sub addTable {
Subroutine addTable: not called CC=6 SCAR=37.4
Pod documented
78 0 my $self = shift @_;
79 0 my $data = shift @_;
80 0 ▶ my $width = shift @_ || '';
Condition0%0/2
shift @_ || ''
l!l
00
MC/DC0%0/1
shift @_ || ''
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
81 0 ▶ my $padding = shift @_ || 5;
Condition0%0/2
shift @_ || 5
l!l
00
MC/DC0%0/1
shift @_ || 5
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
82 0 ▶ my $bgcolor_odd = shift @_ || "#FFFFFF";
Condition0%0/2
shift @_ || '#FFFFFF'
l!l
00
MC/DC0%0/1
shift @_ || '#FFFFFF'
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
83 0 ▶ my $bgcolor_even = shift @_ || "#FFFFCC";
Condition0%0/2
shift @_ || '#FFFFCC'
l!l
00
MC/DC0%0/1
shift @_ || '#FFFFCC'
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
84
85 0 my $pdftable = new PDF::Table;
86
87 # Figure out if it'll fit on the current page (this may need tweaking)
88 0 ▶ if (($self->{report}->{vPos} - (length($data) * ((2 * $padding) + 12))) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"report"}{"vPos"} - length($data) * (2 * $padding + 12) < 0) 0 0 0
89 0 $self->{report}->{vPos} = $self->{report}->{PageHeight} - $self->{report}->{Ymargin};
90 0 $self->{report}->newpage();
91 }
92
93 # Add to page
94 my ($end_page, $pages_spanned, $table_bot_y) = $pdftable->table(
95 # required params
96 $self->{report}->{pdf},
97 $self->{report}->{page},
98 $data,
99 -x => $self->{report}->{hPos},
100 -start_y => $self->{report}->{vPos},
101 -start_h => $self->{report}->{PageHeight},
102 0 -w => $width,
103 -padding => $padding,
104 -background_color_odd => $bgcolor_odd,
105 -background_color_even => $bgcolor_even,
106 );
107
108 # Set baseline for next position
109 0 $self->{report}->{vPos} = $table_bot_y - 20;
110 }
111  
112  
113 1 1;
114 __END__
↑ Summary