SimpleExcel.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 93.3% 42 / 45 CC 6 SCAR 13.3
CC
6
Cov
92%
__ANON__
6.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.8
↑ Summary SimpleExcel/Trait.pm »
1 #
2 # This file is part of CatalystX-Controller-ExtJS-REST-SimpleExcel
3 #
4 # This software is Copyright (c) 2011 by Moritz Onken.
5 #
6 # This is free software, licensed under:
7 #
8 # The (three-clause) BSD License
9 #
10 package CatalystX::Controller::ExtJS::REST::SimpleExcel;
11 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 $CatalystX::Controller::ExtJS::REST::SimpleExcel::VERSION = '0.1.1';
13 }
14 # ABSTRACT: Serialize to Excel spreadsheets
15 2 ▶use Moose::Role -traits => 'CatalystX::Controller::ExtJS::REST::SimpleExcel::Trait';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶after list => sub {
Subroutine __ANON__: called CC=6 SCAR=18.0
21 2 my ($self, $c) = @_;
22 2 ▶ return unless($c->request->accepts('application/vnd.ms-excel'));
Branch: 1 branch
BranchTrueFalseTotal
unless $c->request->accepts("application/vnd.ms-excel") 1 1 2
23 1 my $data = $c->stash->{$self->config->{stash_key}};
24 1 my @header = map { $_->{mapping} } @{$data->{metaData}->{fields}};
25 1 my @rows;
26 1 foreach my $row(@{$data->{$self->root_property}}) {
27 10 my @row;
28 10 foreach my $head(@header) {
29 30 my $rcopy = $row;
30 30 my $hcopy = $head;
31 30 ▶ while($hcopy =~ s/^(\w+)\.//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hcopy =~ s/^(\w+)\.//) 0 30 30
32 0 $rcopy = $rcopy->{$1};
33 }
34 30 ▶ push(@row, ref $rcopy->{$hcopy} ? JSON::XS::encode_json($rcopy->{$hcopy}) : $rcopy->{$hcopy} );
Branch: 1 branch
BranchTrueFalseTotal
ref $rcopy->{$hcopy} ? : 0 30 30
35 }
36 10 push(@rows, \@row);
37 }
38 $c->stash->{$self->config->{stash_key}} = {
39 1 sheets => [{
40 name => $self->default_resultset,
41 header => \@header,
42 rows => \@rows
43 }]
44 };
45 2 };
46  
47 2 1;
48  
49  
50  
51 =pod
52  
53 =head1 NAME
54  
55 CatalystX::Controller::ExtJS::REST::SimpleExcel - Serialize to Excel spreadsheets
56  
57 =head1 VERSION
58  
59 version 0.1.1
60  
61 =head1 SYNOPSIS
62  
63 package MyApp::Controller::User;
64 use Moose;
65 extends 'CatalystX::Controller::ExtJS::REST';
66 with 'CatalystX::Controller::ExtJS::REST::SimpleExcel';
67
68 1;
69  
70 Access C<< /users?content-type=application%2Fvnd.ms-excel >> to get the excel file.
71  
72 =head1 DESCRIPTION
73  
74 This role loads L<Catalyst::Action::Serialize::SimpleExcel> and adds
75 C<< application/vnd.ms-excel >> to the type map. When requesting a list of
76 objects, this role converts the output to satisfy L<Catalyst::Action::Serialize::SimpleExcel>.
77  
78 =head1 SEE ALSO
79  
80 L<CatalystX::Controller::ExtJS::REST>
81  
82 =head1 AUTHOR
83  
84 Moritz Onken
85  
86 =head1 COPYRIGHT AND LICENSE
87  
88 This software is Copyright (c) 2011 by Moritz Onken.
89  
90 This is free software, licensed under:
91  
92 The (three-clause) BSD License
93  
94 =cut
95  
96  
97 __END__
↑ Summary SimpleExcel/Trait.pm »