| 1 | package Dancer::Serializer::YAML; | ||||||||||||
| 2 | 177 | our $AUTHORITY = 'cpan:SUKRIA'; | |||||||||||
| 3 | #ABSTRACT: serializer for handling YAML data | ||||||||||||
| 4 | 177 | $Dancer::Serializer::YAML::VERSION = '1.3522'; | |||||||||||
| 5 | 177 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 177 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 177 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 177 | ▶ | use Dancer::ModuleLoader; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 177 | ▶ | use Dancer::Config; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 177 | ▶ | use Dancer::Exception qw(:all); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 177 | ▶ | use base 'Dancer::Serializer::Abstract'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | # helpers | ||||||||||||
| 14 | |||||||||||||
| 15 | 8 | ▶ | sub from_yaml { | ||||||||||
|
Subroutine
from_yaml: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 16 | 8 | my ($yaml) = @_; | |||||||||||
| 17 | 8 | my $s = Dancer::Serializer::YAML->new; | |||||||||||
| 18 | 8 | $s->deserialize($yaml); | |||||||||||
| 19 | } | ||||||||||||
| 20 | |||||||||||||
| 21 | 4 | ▶ | sub to_yaml { | ||||||||||
|
Subroutine
to_yaml: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 22 | 4 | my ($data) = @_; | |||||||||||
| 23 | 4 | my $s = Dancer::Serializer::YAML->new; | |||||||||||
| 24 | 4 | $s->serialize($data); | |||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | # class definition | ||||||||||||
| 28 | |||||||||||||
| 29 | 16 | ▶ | sub loaded { | ||||||||||
|
Subroutine
loaded: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||
| 30 | 16 | ▶ | my $module = Dancer::Config::settings->{engines}{YAML}{module} || 'YAML'; | ||||||||||
|
Condition100%2/2
Dancer::Config::settings()->{'engines'}{'YAML'}{'module'} || 'YAML'
MC/DC100%1/1
Dancer::Config::settings()->{'engines'}{'YAML'}{'module'} || 'YAML'
Dancer::Config::settings()->{'engines'}{'YAML'}{'module'}
Truth table100%2/2
A
A= Dancer::Config::settings()->{'engines'}{'YAML'}{'module'}
| |||||||||||||
| 31 | |||||||||||||
| 32 | 16 | ▶ | raise core_serializer => q{Dancer::Serializer::YAML only supports 'YAML' or 'YAML::XS', not $module} | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | unless $module =~ /^YAML(?:::XS)?$/; | ||||||||||||
| 34 | |||||||||||||
| 35 | 16 | ▶ | Dancer::ModuleLoader->load($module) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 36 | or raise core_serializer => "$module is needed and is not installed"; | ||||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | 16 | ▶ | sub init { | ||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 40 | 16 | my ($self) = @_; | |||||||||||
| 41 | 16 | $self->loaded; | |||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | 12 | ▶ | sub serialize { | ||||||||||
|
Subroutine
serialize: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 45 | 12 | my ($self, $entity) = @_; | |||||||||||
| 46 | 12 | ▶ | return unless $entity; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | 12 | ▶ | my $module = Dancer::Config::settings->{engines}{YAML}{module} || 'YAML'; | ||||||||||
|
Condition100%2/2
Dancer::Config::settings()->{'engines'}{'YAML'}{'module'} || 'YAML'
MC/DC100%1/1
Dancer::Config::settings()->{'engines'}{'YAML'}{'module'} || 'YAML'
Dancer::Config::settings()->{'engines'}{'YAML'}{'module'}
Truth table100%2/2
A
A= Dancer::Config::settings()->{'engines'}{'YAML'}{'module'}
| |||||||||||||
| 48 | { | ||||||||||||
| 49 | 177 | ▶ | no strict 'refs'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 50 | 12 | &{ $module . '::Dump' }($entity); | |||||||||||
| 51 | } | ||||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 12 | ▶ | sub deserialize { | ||||||||||
|
Subroutine
deserialize: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 55 | 12 | my ($self, $content) = @_; | |||||||||||
| 56 | 12 | ▶ | my $module = Dancer::Config::settings->{engines}{YAML}{module} || 'YAML'; | ||||||||||
|
Condition100%2/2
Dancer::Config::settings()->{'engines'}{'YAML'}{'module'} || 'YAML'
MC/DC100%1/1
Dancer::Config::settings()->{'engines'}{'YAML'}{'module'} || 'YAML'
Dancer::Config::settings()->{'engines'}{'YAML'}{'module'}
Truth table100%2/2
A
A= Dancer::Config::settings()->{'engines'}{'YAML'}{'module'}
| |||||||||||||
| 57 | 12 | ▶ | return unless $content; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | { | ||||||||||||
| 59 | 177 | ▶ | no strict 'refs'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 60 | 10 | &{ $module . '::Load' }($content); | |||||||||||
| 61 | } | ||||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | 6 | ▶ | sub content_type {'text/x-yaml'} | ||||||||||
|
Subroutine
content_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 65 | |||||||||||||
| 66 | 177 | 1; | |||||||||||
| 67 | |||||||||||||
| 68 | __END__ | ||||||||||||