blib/lib/Mojolicious/Plugin/WriteExcel.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 100% 44 / 44 CC 6 SCAR 13.9
CC
6
Cov
100%
xls_renderer
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
↑ Summary
1 package Mojolicious::Plugin::WriteExcel;
2  
3 2 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Spreadsheet::WriteExcel::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '3.00';
7  
8 # You just have to give guys a chance. Sometimes you meet a guy and
9 # think he's a pig, but then later on you realize he actually has a
10 # really good body.
11 5 ▶sub xls_renderer {
Subroutine xls_renderer: called CC=6 SCAR=17.9
Pod documented
12 5 my ($r, $c, $output, $options) = @_;
13  
14 # don't let MojoX::Renderer to encode output to string
15 5 delete $options->{encoding};
16  
17 # tell the renderer we're not html
18 5 $options->{format} = 'xls';
19  
20 5 my $ss = Spreadsheet::WriteExcel::Simple->new;
21 5 my $heading = $c->stash->{heading};
22 5 my $result = $c->stash->{result};
23 5 my $settings = $c->stash->{settings};
24  
25 5 ▶ if (ref $heading) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $heading) 1 4 5
26 1 $ss->write_bold_row($heading);
27 }
28  
29 5 ▶ if (ref $settings) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $settings) 2 3 5
30 die "invalid column width"
31 2 ▶ unless defined $settings->{column_width};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $settings->{"column_width"} 1 1 2
32 1 for my $col (keys %{$settings->{column_width}}) {
33 3 $ss->sheet->set_column($col, $settings->{column_width}->{$col});
34 }
35 }
36  
37 4 foreach my $data (@$result) {
38 9 $ss->write_row($data);
39 }
40  
41 4 $$output = $ss->data;
42  
43 4 return 1;
44 }
45  
46 1 ▶sub register {
Subroutine register: called CC=1 SCAR=0.0
Pod documented
47 1 my ($self, $app) = @_;
48  
49 1 $app->types->type(xls => 'application/vnd.ms-excel');
50 1 $app->renderer->add_handler(xls => \&xls_renderer);
51 $app->helper(
52 1 ▶ render_xls => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
53 1 shift->render(handler => 'xls', @_);
54 }
55 1 );
56 }
57  
58 2 1;
59 __END__
↑ Summary