| 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
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 197 | ▶ | $content or return $content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 193 | my $data; | |||||||||||||||||||||||||||
| 45 | eval { | ||||||||||||||||||||||||||||
| 46 | 193 | $data = $self->$orig( $content, $options ); | |||||||||||||||||||||||||||
| 47 | 191 | ▶ | blessed $self | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | and $self->execute_hook( 'engine.serializer.after', $data ); | ||||||||||||||||||||||||||||
| 49 | 191 | 1; | |||||||||||||||||||||||||||
| 50 | 193 | ▶ | } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 2 | ▶ | my $error = $@ || 'Zombie Error'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$@ || 'Zombie Error'
MC/DC0%0/1
$@ || 'Zombie Error'
$@
Truth table50%1/2
A
A= $@
| |||||||||||||||||||||||||||||
| 52 | 2 | ▶ | if ( blessed($self) && $self->config->{strict_utf8} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($self) and $self->config->{"strict_utf8"}
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"}
| |||||||||||||||||||||||||||||
| 53 | 1 | die $error; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 1 | ▶ | blessed $self | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$content and length $content > 0
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 73 | 9 | ▶ | my $error = $@ || 'Zombie Error'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$@ || 'Zombie Error'
MC/DC0%0/1
$@ || 'Zombie Error'
$@
Truth table50%1/2
A
A= $@
| |||||||||||||||||||||||||||||
| 74 | 9 | ▶ | blessed $self | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||