lib/DBIx/Class/InflateColumn/JSON2Object/Role/Storable.pm

filter: Statementstmt 97.6% 42 / 43 Branchbran 71.4% 10 / 14 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 5 totaltotal 77.3% 65 / 84 CC 11 SCAR 9.4
CC
11
Cov
86%
pack
4.0
__ANON__
3.7
freeze
3.2
CRAP 2.6
« Build ↑ Summary lib/DBIx/Class/InflateColumn/JSON2Object.pm »
1 package DBIx::Class::InflateColumn::JSON2Object::Role::Storable;
2  
3 # ABSTRACT: simplified MooseX::Storage clone with enhanced JSON boolean handling
4  
5 4 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use DBIx::Class::InflateColumn::JSON2Object::Trait::NoSerialize;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use String::CamelCase qw(camelize decamelize);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 subtype 'InflateColumnJSONBool',
14 as 'Ref';
15 coerce 'InflateColumnJSONBool',
16 from 'Str',
17 4 ▶ via { $_ ? JSON->true : JSON->false };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 2 2 4
18 coerce 'InflateColumnJSONBool',
19 from 'Int',
20 0 ▶ via { $_ ? JSON->true : JSON->false };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
21  
22 sub freeze {
23 7 ▶ my ($self) = @_;
Subroutine freeze: called CC=3 SCAR=11.8
Pod undocumented
24  
25 7 my $payload = $self->pack;
26 7 my $json = encode_json($payload);
27  
28 # stolen from MooseX::Storage
29 7 ▶ utf8::decode($json) if !utf8::is_utf8($json) and utf8::valid($json);
Branch: 1 branch
BranchTrueFalseTotal
if not utf8::is_utf8($json) and utf8::valid($json) 7 0 7
Condition33%1/3
not utf8::is_utf8($json) and utf8::valid($json)
!ll&&!rl&&r
007
MC/DC0%0/2
not utf8::is_utf8($json) and utf8::valid($json)
not utf8::is_utf8($json) utf8::valid($json)
Truth table33%1/3
not(A) and B
A= not utf8::is_utf8($json)B= utf8::valid($json)
ABresult
0X0
100
111
30 7 return $json;
31 }
32  
33 sub thaw {
34 9 ▶ my ($class,$payload) = @_;
Subroutine thaw: called CC=3 SCAR=11.0
Pod undocumented
35  
36 # stolen from MooseX::Storage
37 9 ▶ utf8::encode($payload) if utf8::is_utf8($payload);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($payload) 7 2 9
38  
39 9 ▶ $payload = decode_json($payload) unless ref($payload);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $payload 7 2 9
40 9 return $class->new($payload);
41 }
42  
43 sub pack {
44 7 ▶ my ($self) = @_;
Subroutine pack: called CC=4 SCAR=13.9
Pod undocumented
45  
46 7 my $payload = {};
47 7 foreach my $attribute ($self->meta->get_all_attributes) {
48 next
49 20 ▶ if $attribute->does('DBIx::Class::InflateColumn::Trait::NoSerialize');
Branch: 1 branch
BranchTrueFalseTotal
if $attribute->does("DBIx::Class::InflateColumn::Trait::NoSerialize") 0 20 20
50 20 my $val = $attribute->get_value($self);
51 20 ▶ $payload->{$attribute->name} = $val if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 18 2 20
52 }
53 7 return $payload;
54 }
55  
56 sub moniker {
57 2 ▶ my ($self) = @_;
Subroutine moniker: called CC=2 SCAR=7.4
Pod undocumented
58 2 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
59 2 $class =~ /::([^:]+)$/;
60 2 return decamelize($1);
61 }
62  
63 sub package {
64 6 ▶ my ($class,$moniker) = @_;
Subroutine package: called CC=1 SCAR=0.0
Pod undocumented
65 6 return $class.'::'.camelize($moniker)
66 }
67  
68 4 1;
69  
70 __END__
71  
72 =pod
73  
74 =encoding UTF-8
75  
76 =head1 NAME
77  
78 DBIx::Class::InflateColumn::JSON2Object::Role::Storable - simplified MooseX::Storage clone with enhanced JSON boolean handling
79  
80 =head1 VERSION
81  
82 version 0.900
83  
84 =head1 AUTHOR
85  
86 Thomas Klausner <domm@cpan.org>
87  
88 =head1 COPYRIGHT AND LICENSE
89  
90 This software is copyright (c) 2017 by Thomas Klausner.
91  
92 This is free software; you can redistribute it and/or modify it under
93 the same terms as the Perl 5 programming language system itself.
94  
95 =cut
« Build ↑ Summary lib/DBIx/Class/InflateColumn/JSON2Object.pm »