line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Serialize::Serializer; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Role for defining File::Serialize serializers |
4
|
|
|
|
|
|
|
$File::Serialize::Serializer::VERSION = '1.4.0'; |
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
65593
|
use strict; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
199
|
|
7
|
7
|
|
|
7
|
|
34
|
use warnings; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
207
|
|
8
|
|
|
|
|
|
|
|
9
|
7
|
|
|
7
|
|
3721
|
use List::MoreUtils qw/ any all /; |
|
7
|
|
|
|
|
63312
|
|
|
7
|
|
|
|
|
54
|
|
10
|
7
|
|
|
7
|
|
11115
|
use Module::Info; |
|
7
|
|
|
|
|
42843
|
|
|
7
|
|
|
|
|
224
|
|
11
|
7
|
|
|
7
|
|
47
|
use Module::Runtime qw/ use_module /; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
54
|
|
12
|
|
|
|
|
|
|
|
13
|
7
|
|
|
7
|
|
370
|
use Role::Tiny; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
48
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
requires 'extensions'; # first extension is the canonical one |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
requires 'serialize', 'deserialize'; |
18
|
|
|
|
|
|
|
|
19
|
1344
|
|
|
1344
|
1
|
3111
|
sub precedence { 100 } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub required_modules { |
22
|
849
|
|
|
849
|
1
|
1351
|
my $package = shift; |
23
|
849
|
|
|
|
|
3480
|
$package =~ s/^File::Serialize::Serializer:://r; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
5
|
|
|
5
|
0
|
944
|
sub extension { ($_[0]->extensions)[0] } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub does_extension { |
29
|
208
|
|
|
208
|
0
|
419
|
my( $self, $ext ) = @_; |
30
|
208
|
100
|
|
|
|
398
|
return unless $ext; |
31
|
203
|
|
|
290
|
|
931
|
return any { $_ eq $ext } $self->extensions; |
|
290
|
|
|
|
|
897
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub is_operative { |
35
|
513
|
100
|
|
513
|
0
|
29028
|
return 1 unless $_[0]->required_modules; |
36
|
456
|
|
|
513
|
|
1892
|
all { Module::Info->new_from_module($_) } $_[0]->required_modules; |
|
513
|
|
|
|
|
13013
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub groom_serialize_options { |
40
|
29
|
|
|
29
|
1
|
56
|
my $self = shift; |
41
|
29
|
|
|
|
|
109
|
$self->groom_options(@_); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub groom_deserialize_options { |
45
|
34
|
|
|
34
|
1
|
62
|
my $self = shift; |
46
|
34
|
|
|
|
|
111
|
$self->groom_options(@_); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub groom_options { |
50
|
26
|
|
|
26
|
1
|
49
|
my $self = shift; |
51
|
26
|
|
|
|
|
98
|
@_; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
before serialize => \&init; |
55
|
|
|
|
|
|
|
before deserialize => \&init; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
around serialize => sub { |
58
|
|
|
|
|
|
|
my( $orig, $self, $data, $options ) = @_; |
59
|
|
|
|
|
|
|
$orig->( $self, $data, $self->groom_serialize_options($options) ); |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
around deserialize => sub { |
63
|
|
|
|
|
|
|
my( $orig, $self, $data, $options ) = @_; |
64
|
|
|
|
|
|
|
$orig->( $self, $data, $self->groom_deserialize_options($options) ); |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub init { |
68
|
63
|
|
|
63
|
0
|
4917
|
my $self = shift; |
69
|
63
|
|
|
|
|
169
|
use_module($_) for $self->required_modules; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |