line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
1985
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
93
|
|
2
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
113
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Paludis::ResumeState::Serialization::Basic; |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
2
|
|
|
2
|
|
79
|
$Paludis::ResumeState::Serialization::Basic::AUTHORITY = 'cpan:KENTNL'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
{ |
9
|
|
|
|
|
|
|
$Paludis::ResumeState::Serialization::Basic::VERSION = '0.01000410'; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: Basic & Consistent Resume-State serialization interface. |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
12
|
use Paludis::ResumeState::Serialization::Grammar; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
70
|
|
15
|
2
|
|
|
2
|
|
13
|
use Params::Util qw( _HASHLIKE _STRING ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
166
|
|
16
|
2
|
|
|
2
|
|
11
|
use Class::Load 0.06 qw(); |
|
2
|
|
|
|
|
75
|
|
|
2
|
|
|
|
|
64
|
|
17
|
2
|
|
|
2
|
|
14170
|
use English qw( -no_match_vars ); |
|
2
|
|
|
|
|
2139
|
|
|
2
|
|
|
|
|
12
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
## no critic ( RequireArgUnpacking ProhibitUnreachableCode ProhibitMagicNumbers RequireCheckedSyscalls ) |
21
|
|
|
|
|
|
|
sub _debug { |
22
|
|
|
|
|
|
|
|
23
|
117
|
|
|
117
|
|
167
|
return; # Comment this for tracing. |
24
|
0
|
0
|
|
|
|
0
|
return unless Class::Load::load_optional_class('Data::Dumper'); |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
0
|
local $Data::Dumper::Indent = 1; |
27
|
0
|
|
|
|
|
0
|
local $Data::Dumper::Maxdepth = 3; |
28
|
0
|
|
|
|
|
0
|
print Data::Dumper::Dumper( \@_ ); |
29
|
0
|
|
|
|
|
0
|
return 1; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub serialize { |
34
|
3
|
|
|
3
|
1
|
8
|
my ( $self, $data ) = @_; |
35
|
3
|
|
|
|
|
15
|
my $string = _serialize_basic_resumespec($data); |
36
|
3
|
|
|
|
|
24
|
return $string; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub deserialize { |
41
|
6
|
|
|
6
|
1
|
18
|
my ( $self, $content ) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
local $Paludis::ResumeState::Serialization::Grammar::CLASS_CALLBACK = sub { |
44
|
228
|
|
|
228
|
|
425
|
my ( $classname, $parameters, $parameters_list, $extra ) = @_; |
45
|
228
|
|
|
|
|
357
|
return { type => 'class', classname => $classname, parameters => $parameters_list, %{$extra} }; |
|
228
|
|
|
|
|
11865
|
|
46
|
6
|
|
|
|
|
40
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
local $Paludis::ResumeState::Serialization::Grammar::LIST_CALLBACK = sub { |
49
|
132
|
|
|
132
|
|
304
|
my ($parameters) = @_; |
50
|
132
|
|
|
|
|
225
|
return { type => 'array', parameters => $parameters, count => scalar @{$parameters} }; |
|
132
|
|
|
|
|
6107
|
|
51
|
6
|
|
|
|
|
34
|
}; |
52
|
6
|
|
|
|
|
13
|
my $results; |
53
|
6
|
|
|
|
|
35
|
my $grammar = Paludis::ResumeState::Serialization::Grammar::grammar(); |
54
|
6
|
|
|
|
|
20
|
local (%RS) = (); |
55
|
|
|
|
|
|
|
|
56
|
6
|
50
|
|
|
|
407
|
if ( $content =~ $grammar ) { |
57
|
6
|
|
|
|
|
27
|
$results = \%RS; |
58
|
6
|
|
|
|
|
155
|
return $results; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _serialize_basic_array { |
65
|
66
|
|
|
66
|
|
73
|
my $data = shift; |
66
|
66
|
|
|
|
|
89
|
my $out = 'c('; |
67
|
66
|
|
|
|
|
80
|
my $i = 1; |
68
|
66
|
|
|
|
|
104
|
my @pairs = (); |
69
|
66
|
|
|
|
|
73
|
for my $value ( @{ $data->{parameters} } ) { |
|
66
|
|
|
|
|
188
|
|
70
|
119
|
|
|
|
|
149
|
my $key = $i; |
71
|
119
|
|
|
|
|
122
|
$i++; |
72
|
119
|
|
|
|
|
227
|
push @pairs, sprintf q{%s=%s;}, $key, _serialize_basic_value($value); |
73
|
|
|
|
|
|
|
} |
74
|
66
|
|
|
|
|
168
|
push @pairs, 'count=' . _serialize_basic_value( $data->{count} ) . q{;}; |
75
|
66
|
|
|
|
|
536
|
$out .= ( join q{}, @pairs ); |
76
|
66
|
|
|
|
|
76
|
$out .= ')'; |
77
|
66
|
|
|
|
|
336
|
return $out; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _serialize_basic_class { |
81
|
111
|
|
|
111
|
|
130
|
my $data = shift; |
82
|
111
|
|
|
|
|
548
|
my $out = $data->{classname} . '('; |
83
|
111
|
|
|
|
|
276
|
$out .= _serialize_basic_parameters( $data->{parameters} ); |
84
|
111
|
|
|
|
|
165
|
$out .= ')'; |
85
|
111
|
|
|
|
|
686
|
return $out; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _serialize_basic_value { |
89
|
453
|
|
|
453
|
|
572
|
my $value = shift; |
90
|
453
|
100
|
|
|
|
6737
|
if ( defined _STRING($value) ) { |
91
|
276
|
|
|
|
|
368
|
$value =~ s/"/\\"/gmsx; |
92
|
276
|
|
|
|
|
1229
|
return sprintf q{"%s"}, $value; |
93
|
|
|
|
|
|
|
} |
94
|
177
|
50
|
|
|
|
496
|
if ( _HASHLIKE($value) ) { |
95
|
177
|
100
|
66
|
|
|
940
|
if ( defined $value->{type} and $value->{type} eq 'class' ) { |
96
|
111
|
|
|
|
|
219
|
return _serialize_basic_class($value); |
97
|
|
|
|
|
|
|
} |
98
|
66
|
50
|
33
|
|
|
316
|
if ( defined $value->{type} and $value->{type} eq 'array' ) { |
99
|
66
|
|
|
|
|
140
|
return _serialize_basic_array($value); |
100
|
|
|
|
|
|
|
} |
101
|
0
|
|
|
|
|
0
|
Carp::croak("UNEXPECTED PARAMETER TYPE: $value->{type} "); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
0
|
Carp::croak("UNEXPECTED PARAMETER VALUE: $value"); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub _serialize_basic_parameters { |
109
|
114
|
|
|
114
|
|
155
|
my $data = shift; |
110
|
114
|
|
|
|
|
2347
|
_debug( 'serialize_basic_parameters', $data ); |
111
|
|
|
|
|
|
|
|
112
|
114
|
|
|
|
|
147
|
my @pairs = (); |
113
|
114
|
|
|
|
|
140
|
for my $kv_pair ( @{$data} ) { |
|
114
|
|
|
|
|
250
|
|
114
|
268
|
|
|
|
|
294
|
my ( $key, $value ) = @{$kv_pair}; |
|
268
|
|
|
|
|
654
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# my $value = $data->{$key}; |
117
|
268
|
|
|
|
|
528
|
push @pairs, sprintf q{%s=%s;}, $key, _serialize_basic_value($value); |
118
|
|
|
|
|
|
|
} |
119
|
114
|
|
|
|
|
469
|
return ( join q{}, @pairs ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _serialize_basic_resumespec { |
123
|
3
|
|
|
3
|
|
8
|
my $data = shift; |
124
|
3
|
|
|
|
|
17
|
_debug( 'serialize_basic_resumespec', $data ); |
125
|
3
|
50
|
|
|
|
19
|
return unless _HASHLIKE($data); |
126
|
3
|
50
|
|
|
|
16
|
return unless defined $data->{ResumeSpec}; |
127
|
3
|
50
|
|
|
|
17
|
return unless defined $data->{ResumeSpec}->{classname}; |
128
|
3
|
50
|
33
|
|
|
35
|
return unless defined $data->{ResumeSpec}->{type} and $data->{ResumeSpec}->{type} eq 'class'; |
129
|
3
|
50
|
|
|
|
14
|
return unless defined $data->{ResumeSpec}->{parameters}; |
130
|
3
|
50
|
|
|
|
15
|
return unless defined $data->{ResumeSpec}->{pid}; |
131
|
3
|
|
|
|
|
12
|
my $out = $data->{ResumeSpec}->{classname} . q{@} . $data->{ResumeSpec}->{pid}; |
132
|
3
|
|
|
|
|
7
|
$out .= '('; |
133
|
3
|
|
|
|
|
15
|
$out .= _serialize_basic_parameters( $data->{ResumeSpec}->{parameters} ); |
134
|
3
|
|
|
|
|
15
|
$out .= ');'; |
135
|
3
|
|
|
|
|
15
|
return $out; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
__END__ |