File Coverage

blib/lib/DBIx/DataModel/Schema/ResultAs/Json.pm
Criterion Covered Total %
statement 25 25 100.0
branch 1 2 50.0
condition n/a
subroutine 8 8 100.0
pod 1 2 50.0
total 35 37 94.5


line stmt bran cond sub pod time code
1             #----------------------------------------------------------------------
2             package DBIx::DataModel::Schema::ResultAs::Json;
3             #----------------------------------------------------------------------
4 1     1   596 use warnings;
  1         4  
  1         35  
5 1     1   6 use strict;
  1         2  
  1         25  
6 1     1   6 use Carp::Clan qw[^(DBIx::DataModel::|SQL::Abstract)];
  1         2  
  1         7  
7 1     1   82 use JSON::MaybeXS ();
  1         2  
  1         44  
8              
9 1     1   7 use parent 'DBIx::DataModel::Schema::ResultAs';
  1         2  
  1         5  
10              
11 1     1   65 use namespace::clean;
  1         3  
  1         7  
12              
13             sub new {
14 1     1 0 3 my ($class, %json_options) = @_;
15 1 50       8 keys %json_options
16             or %json_options = ( pretty => 1,
17             allow_blessed => 1,
18             convert_blessed => 1 );
19 1         3 return bless \%json_options, $class;
20             }
21              
22              
23             sub get_result {
24 1     1 1 3 my ($self, $statement) = @_;
25              
26 1         16 my $json_maker = JSON::MaybeXS->new(%$self);
27 1         37 my $json = $json_maker->encode($statement->all);
28 1         20 return $json;
29             }
30              
31              
32             1;
33              
34             __END__