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

filter: Statementstmt 95.6% 44 / 46 Branchbran 83.3% 15 / 18 Conditioncond 60.0% 6 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 2 totaltotal 81.5% 75 / 92 CC 14 SCAR 17.3
CC
14
Cov
88%
__ANON__
9.4
__ANON__
6.0
_build_type
2.0
CRAP 5.6
« blib/lib/Dancer2/Template/TemplateToolkit.pm ↑ Summary lib/Dancer2/Core/Role/HasLocation.pm »
1 package Dancer2::Core::Role::Serializer;
2 # ABSTRACT: Role for Serializer engines
3 39 $Dancer2::Core::Role::Serializer::VERSION = '2.3.0';
4 39 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 39 ▶use Dancer2::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 39 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 39 with 'Dancer2::Core::Role::Engine';
9  
10 497 ▶sub hook_aliases {
Subroutine hook_aliases: called CC=1 SCAR=0.0
Pod undocumented
11 {
12 497 before_serializer => 'engine.serializer.before',
13 after_serializer => 'engine.serializer.after',
14 }
15 }
16  
17 109 ▶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 39 requires 'serialize';
22 39 requires 'deserialize';
23  
24 has log_cb => (
25 is => 'ro',
26 isa => CodeRef,
27 0 ▶ default => sub { sub {1} },
Subroutine __ANON__: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=1.2
28 39 );
29  
30 39 has content_type => (
31 is => 'ro',
32 isa => Str,
33 required => 1,
34 writer => 'set_content_type'
35 );
36  
37 197 ▶around serialize => sub {
Subroutine __ANON__: called CC=9 SCAR=22.4
38 197 my ( $orig, $self, $content, $options ) = @_;
39  
40 197 ▶ blessed $self && $self->execute_hook( 'engine.serializer.before', $content );
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) and $self->execute_hook("engine.serializer.before", $content) 197 0 197
41  
42 197 ▶ $content or return $content;
Branch: 1 branch
BranchTrueFalseTotal
$content or return $content 193 4 197
43  
44 193 my $data;
45 eval {
46 193 $data = $self->$orig( $content, $options );
47 191 ▶ blessed $self
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) and $self->execute_hook("engine.serializer.after", $data) 191 0 191
48 and $self->execute_hook( 'engine.serializer.after', $data );
49 191 1;
50 193 ▶ } 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") } 191 2 193
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 192 return $data;
60 39 };
61  
62 80 ▶around deserialize => sub {
Subroutine __ANON__: called CC=6 SCAR=18.0
63 80 my ( $orig, $self, $content, $options ) = @_;
64  
65 80 ▶ $content && length $content > 0
Branch: 1 branch
BranchTrueFalseTotal
$content and length $content > 0 or return $content 78 2 80
Condition66%2/3
$content and length $content > 0
!ll&&!rl&&r
2078
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 78 my $data;
69 eval {
70 78 $data = $self->$orig($content, $options);
71 69 1;
72 78 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $data = $self->$orig($content, $options); 1 } } or do { my $error = $@ || "Zombie Error"; builtin::blessed($self) and $self->log_cb->("core", "Failed to deserialize content: $error") } 69 9 78
73 9 ▶ my $error = $@ || 'Zombie Error';
Condition50%1/2
$@ || 'Zombie Error'
l!l
90
MC/DC0%0/1
$@ || 'Zombie Error'
$@
Truth table50%1/2
A
A= $@
Aresult
11
00
74 9 ▶ blessed $self
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) and $self->log_cb->("core", "Failed to deserialize content: $error") 8 1 9
75 and $self->log_cb->( core => "Failed to deserialize content: $error" );
76 };
77  
78 78 return $data;
79 39 };
80  
81 39 1;
82  
83 __END__
« blib/lib/Dancer2/Template/TemplateToolkit.pm ↑ Summary lib/Dancer2/Core/Role/HasLocation.pm »