blib/lib/Dancer2/Core/Role/Serializer.pm

filter: Statementstmt 97.8% 45 / 46 Branchbran 93.7% 15 / 16 Conditioncond 60.0% 6 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 2 totaltotal 85.3% 76 / 89 CC 13 SCAR 17.0
CC
13
Cov
92%
__ANON__
9.1
__ANON__
5.0
_build_type
2.0
CRAP 5.5
« blib/lib/Dancer2/Template/TemplateToolkit.pm ↑ Summary blib/lib/Dancer2/Core/Role/HasLocation.pm »
1 package Dancer2::Core::Role::Serializer;
2 # ABSTRACT: Role for Serializer engines
3 35 $Dancer2::Core::Role::Serializer::VERSION = '2.2.1';
4 35 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use Dancer2::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 35 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 35 with 'Dancer2::Core::Role::Engine';
9  
10 sub hook_aliases {
11 {
12 291 ▶ before_serializer => 'engine.serializer.before',
Subroutine hook_aliases: called CC=1 SCAR=0.0
Pod undocumented
13 after_serializer => 'engine.serializer.after',
14 }
15 }
16  
17 41 ▶sub supported_hooks { values %{ shift->hook_aliases } }
Subroutine supported_hooks: called CC=1 SCAR=0.0
Pod undocumented
18  
19 0 ▶sub _build_type {'Serializer'}
Subroutine _build_type: not called CC=1 SCAR=6.9
20  
21 35 requires 'serialize';
22 35 requires 'deserialize';
23  
24 has log_cb => (
25 is => 'ro',
26 isa => CodeRef,
27 7 ▶ default => sub { sub {1} },
Subroutine __ANON__: called CC=1 SCAR=0.0
28 35 );
29  
30 35 has content_type => (
31 is => 'ro',
32 isa => Str,
33 required => 1,
34 writer => 'set_content_type'
35 );
36  
37 around serialize => sub {
38 184 ▶ my ( $orig, $self, $content, $options ) = @_;
Subroutine __ANON__: called CC=9 SCAR=22.1
39  
40 184 ▶ blessed $self && $self->execute_hook( 'engine.serializer.before', $content );
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) and $self->execute_hook("engine.serializer.before", $content) 128 56 184
41  
42 184 ▶ $content or return $content;
Branch: 1 branch
BranchTrueFalseTotal
$content or return $content 4 180 184
43  
44 180 my $data;
45 eval {
46 180 $data = $self->$orig( $content, $options );
47 178 ▶ blessed $self
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) and $self->execute_hook("engine.serializer.after", $data) 122 56 178
48 and $self->execute_hook( 'engine.serializer.after', $data );
49 178 1;
50 180 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $data = $self->$orig($content, $options); builtin::blessed($self) and $self->execute_hook("engine.serializer.after", $data); 1 } } or do { my $error = $@ || "Zombie Error"; if (builtin::blessed($self) and $self->config->{"strict_utf8"}) { die $error; } ; builtin::blessed($self) and $self->log_cb->("core", "Failed to serialize content: $error") } 2 178 180
51 2 ▶ my $error = $@ || 'Zombie Error';
Condition50%1/2
$@ || 'Zombie Error'
l!l
20
MC/DC0%0/1
$@ || 'Zombie Error'
$@
Truth table50%1/2
A
A= $@
Aresult
11
00
52 2 ▶ if ( blessed($self) && $self->config->{strict_utf8} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($self) and $self->config->{"strict_utf8"}) 1 1 2
Condition66%2/3
builtin::blessed($self) and $self->config->{"strict_utf8"}
!ll&&!rl&&r
011
MC/DC50%1/2
builtin::blessed($self) and $self->config->{"strict_utf8"}
builtin::blessed($self) $self->config->{"strict_utf8"}
Truth table66%2/3
A and B
A= builtin::blessed($self)B= $self->config->{"strict_utf8"}
ABresult
0X0
100
111
53 1 die $error;
54 }
55 1 ▶ blessed $self
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) and $self->log_cb->("core", "Failed to serialize content: $error") 1 0 1
56 and $self->log_cb->( core => "Failed to serialize content: $error" );
57 };
58  
59 179 return $data;
60 35 };
61  
62 around deserialize => sub {
63 73 ▶ my ( $orig, $self, $content, $options ) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.2
64  
65 73 ▶ $content && length $content > 0
Branch: 1 branch
BranchTrueFalseTotal
$content and length $content > 0 or return $content 2 71 73
Condition66%2/3
$content and length $content > 0
!ll&&!rl&&r
2071
MC/DC50%1/2
$content and length $content > 0
$content length $content > 0
Truth table66%2/3
A and B
A= $contentB= length $content > 0
ABresult
0X0
100
111
66 or return $content;
67  
68 71 my $data;
69 eval {
70 71 $data = $self->$orig($content, $options);
71 66 1;
72 71 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $data = $self->$orig($content, $options); 1 } } or do { my $error = $@ || "Zombie Error"; $self->log_cb->("core", "Failed to deserialize content: $error") } 5 66 71
73 5 ▶ my $error = $@ || 'Zombie Error';
Condition50%1/2
$@ || 'Zombie Error'
l!l
50
MC/DC0%0/1
$@ || 'Zombie Error'
$@
Truth table50%1/2
A
A= $@
Aresult
11
00
74 5 $self->log_cb->( core => "Failed to deserialize content: $error" );
75 };
76  
77 71 return $data;
78 35 };
79  
80 35 1;
81  
82 __END__
« blib/lib/Dancer2/Template/TemplateToolkit.pm ↑ Summary blib/lib/Dancer2/Core/Role/HasLocation.pm »