Helper/Row/ToJSON.pm

filter: Statementstmt 100% 32 / 32 Branchbran 87.5% 7 / 8 Conditioncond 66.6% 4 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 90.0% 54 / 60 CC 7 SCAR 8.7
CC
7
Cov
93%
_is_column_serializable
4.0
serializable_columns
2.0
TO_JSON
2.0
CRAP 2.4
« Helper/ResultSet/Shortcut/Search/Base.pm ↑ Summary Helper/Row/OnColumnMissing.pm »
1 package DBIx::Class::Helper::Row::ToJSON;
2 56 $DBIx::Class::Helper::Row::ToJSON::VERSION = '2.037000';
3 # ABSTRACT: Remove the boilerplate from your TO_JSON functions
4  
5 56 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 56 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 56 ▶use parent 'DBIx::Class::Row';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 56 __PACKAGE__->mk_group_accessors(inherited => '_serializable_columns');
11 56 __PACKAGE__->mk_group_accessors(inherited => '_unserializable_data_types');
12  
13 56 my $dont_serialize = {
14 text => 1,
15 ntext => 1,
16 blob => 1,
17 };
18  
19 42 ▶sub _is_column_serializable {
Subroutine _is_column_serializable: called CC=4 SCAR=13.9
20 42 my ( $self, $column ) = @_;
21  
22 42 my $info = $self->column_info($column);
23  
24 42 ▶ if (!defined $info->{is_serializable}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $info->{"is_serializable"}) 11 31 42
25 11 ▶ if (defined $info->{data_type} &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $info->{'data_type'} and $self->unserializable_data_types->{lc $info->{'data_type'}}) { } 1 10 11
Condition66%2/3
defined $info->{"data_type"} and $self->unserializable_data_types->{lc $info->{"data_type"}}
!ll&&!rl&&r
0101
MC/DC50%1/2
defined $info->{"data_type"} and $self->unserializable_data_types->{lc $info->{"data_type"}}
defined $info->{"data_type"} $self->unserializable_data_types->{lc $info->{"data_type"}}
Truth table66%2/3
A and B
A= defined $info->{"data_type"}B= $self->unserializable_data_types->{lc $info->{"data_type"}}
ABresult
0X0
100
111
26 $self->unserializable_data_types->{lc $info->{data_type}}
27 ) {
28 1 $info->{is_serializable} = 0;
29 } else {
30 10 $info->{is_serializable} = 1;
31 }
32 }
33  
34 42 return $info->{is_serializable};
35 }
36  
37 14 ▶sub serializable_columns {
Subroutine serializable_columns: called CC=2 SCAR=7.0
Pod documented
38 14 my $self = shift;
39 14 ▶ if (!$self->_serializable_columns) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_serializable_columns) 14 0 14
40 14 $self->_serializable_columns([
41 grep $self->_is_column_serializable($_),
42 $self->result_source->columns
43 ]);
44 }
45 14 return $self->_serializable_columns;
46 }
47  
48 14 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=2 SCAR=7.0
Pod documented
49 14 my $self = shift;
50  
51 14 my $columns_info = $self->columns_info($self->serializable_columns);
52  
53 return {
54 map +($_ => $self->$_),
55 14 ▶ map +($columns_info->{$_}{accessor} || $_),
Condition66%2/3
$columns_info->{$_}{'accessor'} || $_
l!l&&r!l&&!r
3360
MC/DC0%0/2
$columns_info->{$_}{'accessor'} || $_
$columns_info->{$_}{'accessor'} $_
Truth table66%2/3
A || B
A= $columns_info->{$_}{'accessor'}B= $_
ABresult
1X1
011
000
56 keys %$columns_info
57 };
58 }
59  
60 9 ▶sub unserializable_data_types {
Subroutine unserializable_data_types: called CC=2 SCAR=6.9
Pod documented
61 9 my $self = shift;
62 9 ▶ if (!$self->_unserializable_data_types) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_unserializable_data_types) 3 6 9
63 3 $self->_unserializable_data_types($dont_serialize);
64 }
65 9 return $self->_unserializable_data_types;
66 }
67  
68 56 1;
69  
70 __END__
« Helper/ResultSet/Shortcut/Search/Base.pm ↑ Summary Helper/Row/OnColumnMissing.pm »