blib/lib/DBIx/Class/ResultSet/Excel.pm

filter: Statementstmt 39.0% 16 / 41 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 36.2% 21 / 58 CC 8 SCAR 38.0
CC
8
Cov
31%
export_excel
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 44.7
↑ Summary
1 package DBIx::Class::ResultSet::Excel;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use 5.008_005;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our $VERSION = '0.01';
6  
7 BEGIN {
8 1 ▶ use base 'DBIx::Class::ResultSet';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶ use File::Temp qw/tempfile/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶ use Spreadsheet::WriteExcel;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 };
12  
13  
14 0 ▶sub export_excel {
Subroutine export_excel: not called CC=8 SCAR=42.8
Pod undocumented
15 0 my $self = shift;
16 0 my %options = @_;
17  
18 0 ▶ my $filename = ($options{'filename'}) ? $options{'filename'} : '';
Branch: 1 branch
BranchTrueFalseTotal
$options{'filename'} ? : 0 0 0
19  
20 0 my $fh; # Filehandle for the resulting excel file
21  
22 # load up temp file
23 0 ▶ if ($filename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename) { } 0 0 0
24 # if filename give, load that file
25 0 ▶ open($fh, ">", $filename) or die "cannot open $filename: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $filename or die "cannot open ${filename}: $!" 0 0 0
26 } else {
27 # if no file give, create temple file.
28 0 ( $fh, $filename ) = tempfile();
29 }
30  
31 0 my $source = $self->result_source;
32  
33 0 my $columns = $source->columns_info;
34  
35 # Create our new workbook
36 0 ▶ my $workbook = Spreadsheet::WriteExcel->new($fh) or die "Problems creating new Excel file: $! : $filename";
Branch: 1 branch
BranchTrueFalseTotal
my $workbook = "Spreadsheet::WriteExcel"->new($fh) or die "Problems creating new Excel file: $! : $filename" 0 0 0
37  
38 # Create a worksheet
39 0 my $worksheet = $workbook->add_worksheet();
40  
41 # Create Bold formating
42 0 my $bold = $workbook->add_format();
43 0 $bold->set_bold();
44  
45 # Construct the header of the excel file
46 0 my $column_cnt = 0;
47 0 foreach my $column ( keys %$columns ) {
48 0 $worksheet->write(0, $column_cnt, $column, $bold);
49 # Increment counter
50 0 $column_cnt++;
51 }
52  
53 # Add Data for each row
54 0 my $row_cnt = 1; # Starts at 1 because 0 is taken by headers
55 0 ▶ while (my $row = $self->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $self->next) 0 0 0
56 # Loop through each column
57 0 $column_cnt = 0;
58 0 foreach my $column ( keys %$columns ) {
59 0 $worksheet->write($row_cnt, $column_cnt, $row->$column);
60 # Increment counter
61 0 $column_cnt++;
62 }
63  
64 # Increment counter
65 0 $row_cnt ++;
66 }
67  
68 0 return ( $fh, $filename );
69 }
70  
71 1 1;
72 __END__
↑ Summary