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