lib/Grimlock/Web/View/JSON.pm

filter: Statementstmt 48.3% 15 / 31 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 44.4% 4 / 9 Podpod 33.3% 1 / 3 totaltotal 44.4% 20 / 45 CC 2 SCAR 8.8
CC
2
Cov
45%
encode_json
6.0
process
2.0
__ANON__
2.0
CRAP 2.4
« lib/Grimlock/Web/Controller/User.pm ↑ Summary lib/Grimlock/Schema/Result/Entry.pm »
1 package Grimlock::Web::View::JSON;
2 {
3 5 $Grimlock::Web::View::JSON::VERSION = '0.11';
4 }
5  
6 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use base 'Catalyst::View::JSON';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub encode_json {
Subroutine encode_json: not called CC=2 SCAR=17.9
Pod undocumented
12 0 my($self, $c, $data) = @_;
13 0 my $encoder = JSON::XS->new->ascii->allow_nonref->convert_blessed->allow_blessed;
14 0 ▶ $encoder->pretty if $c->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $c->debug 0 0 0
15 0 my $d = $encoder->encode($data);
16 0 return $d;
17 }
18
19 0 ▶sub process {
Subroutine process: not called CC=1 SCAR=6.9
Pod documented
20 0 my ( $self, $c, $stash_key ) = @_;
21
22 0 my $output;
23 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 0 $output = $self->serialize( $c, $c->stash->{$stash_key} );
25 0 $c->response->body( $output );
26 0 return 1;
27 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 $c->log->error("Couldn't serialize: $_");
29 0 return $_;
30 0 };
31 }
32
33 0 ▶sub serialize {
Subroutine serialize: not called CC=1 SCAR=6.9
Pod undocumented
34 0 my ( $self, $c, $data ) = @_;
35
36 0 my $serialized = $self->encode_json($c, $data);
37 0 return $serialized;
38 }
39  
40  
41 =head1 NAME
42  
43 Grimlock::Web::View::JSON - Catalyst JSON View
44  
45 =head1 SYNOPSIS
46  
47 See L<Grimlock::Web>
48  
49 =head1 DESCRIPTION
50  
51 Catalyst JSON View.
52  
53 =head1 AUTHOR
54  
55 Devin Austin
56  
57 =head1 LICENSE
58  
59 This library is free software, you can redistribute it and/or modify
60 it under the same terms as Perl itself.
61  
62 =cut
63  
64 5 1;
« lib/Grimlock/Web/Controller/User.pm ↑ Summary lib/Grimlock/Schema/Result/Entry.pm »