line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Starch::Plugin::Sereal; |
2
|
1
|
|
|
1
|
|
5560
|
use 5.008001; |
|
1
|
|
|
|
|
5
|
|
3
|
1
|
|
|
1
|
|
6
|
use strictures 2; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
41
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Starch::Plugin::Sereal - Use Sereal for cloning and diffing Starch data structures. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $starch = Starch->new( |
13
|
|
|
|
|
|
|
plugins => ['::Sereal'], |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
By default L and L |
19
|
|
|
|
|
|
|
use L to do the heavy lifting. This module replaces those two methods |
20
|
|
|
|
|
|
|
with ones that use L which can be leaps and bounds faster than Storable. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
In this author's testing C will be about 3x faster with Sereal and |
23
|
|
|
|
|
|
|
C will be about 1.5x faster with Sereal. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
249
|
use Sereal::Encoder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
28
|
1
|
|
|
1
|
|
7
|
use Sereal::Decoder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
29
|
1
|
|
|
1
|
|
6
|
use Types::Standard -types; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
5079
|
use Moo::Role; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
9
|
|
32
|
1
|
|
|
1
|
|
475
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
with 'Starch::Plugin::ForManager'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 MANAGER ATTRIBUTES |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
These attributes are added to the L class. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 sereal_encoder |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
An instance of L. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has sereal_encoder => ( |
47
|
|
|
|
|
|
|
is => 'lazy', |
48
|
|
|
|
|
|
|
isa => InstanceOf[ 'Sereal::Encoder' ], |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
sub _build_sereal_encoder { |
51
|
3
|
|
|
3
|
|
279
|
return Sereal::Encoder->new(); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 sereal_decoder |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
An instance of L. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
has sereal_decoder => ( |
61
|
|
|
|
|
|
|
is => 'lazy', |
62
|
|
|
|
|
|
|
isa => InstanceOf[ 'Sereal::Decoder' ], |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
sub _build_sereal_decoder { |
65
|
3
|
|
|
3
|
|
149
|
return Sereal::Decoder->new(); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 canonical_sereal_encoder |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
An instance of L with the C option set. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
has canonical_sereal_encoder => ( |
75
|
|
|
|
|
|
|
is => 'lazy', |
76
|
|
|
|
|
|
|
isa => InstanceOf[ 'Sereal::Encoder' ], |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
sub _build_canonical_sereal_encoder { |
79
|
3
|
|
|
3
|
|
109
|
return Sereal::Encoder->new({ canonical => 1 }); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 MODIFIED MANAGER METHODS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
These methods are added to the L class. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 clone_data |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Modified to use L and L to clone |
89
|
|
|
|
|
|
|
a data structure. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub clone_data { |
94
|
48
|
|
|
48
|
1
|
4133949
|
my ($self, $data) = @_; |
95
|
|
|
|
|
|
|
|
96
|
48
|
|
|
|
|
820
|
return $self->sereal_decoder->decode( |
97
|
|
|
|
|
|
|
$self->sereal_encoder->encode( $data ), |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 is_data_diff |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Modified to use L to encode the two data |
104
|
|
|
|
|
|
|
structures. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub is_data_diff { |
109
|
31
|
|
|
31
|
1
|
8536
|
my ($self, $old, $new) = @_; |
110
|
|
|
|
|
|
|
|
111
|
31
|
|
|
|
|
532
|
my $encoder = $self->canonical_sereal_encoder(); |
112
|
|
|
|
|
|
|
|
113
|
31
|
|
|
|
|
435
|
$old = $encoder->encode( $old ); |
114
|
31
|
|
|
|
|
179
|
$new = $encoder->encode( $new ); |
115
|
|
|
|
|
|
|
|
116
|
31
|
100
|
|
|
|
134
|
return 0 if $new eq $old; |
117
|
23
|
|
|
|
|
84
|
return 1; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
__END__ |