| 1 | package File::Serialize::Serializer; | ||||||||||
| 2 | 17 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||
| 3 | # ABSTRACT: Role for defining File::Serialize serializers | ||||||||||
| 4 | 17 | $File::Serialize::Serializer::VERSION = '1.5.0'; | |||||||||
| 5 | |||||||||||
| 6 | 17 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 17 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 17 | ▶ | use List::MoreUtils qw/ any all /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 17 | ▶ | use Module::Info; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 17 | ▶ | use Module::Runtime qw/ use_module /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 17 | ▶ | use Role::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 17 | requires 'extensions'; # first extension is the canonical one | |||||||||
| 16 | |||||||||||
| 17 | 17 | requires 'serialize', 'deserialize'; | |||||||||
| 18 | |||||||||||
| 19 | 1344 | ▶ | sub precedence { 100 } | ||||||||
|
Subroutine
precedence: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 20 | |||||||||||
| 21 | sub required_modules { | ||||||||||
| 22 | 849 | ▶ | my $package = shift; | ||||||||
|
Subroutine
required_modules: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 23 | 849 | $package =~ s/^File::Serialize::Serializer:://r; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 5 | ▶ | sub extension { ($_[0]->extensions)[0] } | ||||||||
|
Subroutine
extension: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 27 | |||||||||||
| 28 | sub does_extension { | ||||||||||
| 29 | 208 | ▶ | my( $self, $ext ) = @_; | ||||||||
|
Subroutine
does_extension: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 30 | 208 | ▶ | return unless $ext; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 203 | ▶ | return any { $_ eq $ext } $self->extensions; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | sub is_operative { | ||||||||||
| 35 | 513 | ▶ | return 1 unless $_[0]->required_modules; | ||||||||
|
Subroutine
is_operative: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||
| 36 | 456 | ▶ | all { Module::Info->new_from_module($_) } $_[0]->required_modules; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | sub groom_serialize_options { | ||||||||||
| 40 | 29 | ▶ | my $self = shift; | ||||||||
|
Subroutine
groom_serialize_options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 41 | 29 | $self->groom_options(@_); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | sub groom_deserialize_options { | ||||||||||
| 45 | 34 | ▶ | my $self = shift; | ||||||||
|
Subroutine
groom_deserialize_options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 46 | 34 | $self->groom_options(@_); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | sub groom_options { | ||||||||||
| 50 | 26 | ▶ | my $self = shift; | ||||||||
|
Subroutine
groom_options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 51 | 26 | @_; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 17 | before serialize => \&init; | |||||||||
| 55 | 17 | before deserialize => \&init; | |||||||||
| 56 | |||||||||||
| 57 | around serialize => sub { | ||||||||||
| 58 | 29 | ▶ | my( $orig, $self, $data, $options ) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 59 | 29 | $orig->( $self, $data, $self->groom_serialize_options($options) ); | |||||||||
| 60 | 17 | }; | |||||||||
| 61 | |||||||||||
| 62 | around deserialize => sub { | ||||||||||
| 63 | 34 | ▶ | my( $orig, $self, $data, $options ) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 34 | $orig->( $self, $data, $self->groom_deserialize_options($options) ); | |||||||||
| 65 | 17 | }; | |||||||||
| 66 | |||||||||||
| 67 | sub init { | ||||||||||
| 68 | 63 | ▶ | my $self = shift; | ||||||||
|
Subroutine
init: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 69 | 63 | use_module($_) for $self->required_modules; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 17 | 1; | |||||||||
| 73 | |||||||||||
| 74 | __END__ | ||||||||||