line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Starch::Plugin::Sereal; |
2
|
|
|
|
|
|
|
$Starch::Plugin::Sereal::VERSION = '0.02'; |
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Starch::Plugin::Sereal - Use Sereal for cloning and diffing Starch data structures. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $starch = Starch->new( |
10
|
|
|
|
|
|
|
plugins => ['::Sereal'], |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
By default L and L |
16
|
|
|
|
|
|
|
use L to do the heavy lifting. This module replaces those two methods |
17
|
|
|
|
|
|
|
with ones that use L which can be leaps and bounds faster than Storable. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
In this author's testing C will be about 3x faster with Sereal and |
20
|
|
|
|
|
|
|
C will be about 1.5x faster with Sereal. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
8084
|
use Sereal::Encoder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
57
|
|
25
|
1
|
|
|
1
|
|
5
|
use Sereal::Decoder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
26
|
1
|
|
|
1
|
|
22
|
use Types::Standard -types; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
3061
|
use Moo::Role; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
29
|
1
|
|
|
1
|
|
347
|
use strictures 2; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
54
|
|
30
|
1
|
|
|
1
|
|
225
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
with qw( |
33
|
|
|
|
|
|
|
Starch::Plugin::ForManager |
34
|
|
|
|
|
|
|
); |
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
|
|
659
|
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
|
|
705
|
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
|
|
681
|
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
|
4130297
|
my ($self, $data) = @_; |
95
|
|
|
|
|
|
|
|
96
|
48
|
|
|
|
|
164
|
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
|
8354
|
my ($self, $old, $new) = @_; |
110
|
|
|
|
|
|
|
|
111
|
31
|
|
|
|
|
98
|
my $encoder = $self->canonical_sereal_encoder(); |
112
|
|
|
|
|
|
|
|
113
|
31
|
|
|
|
|
1054
|
$old = $encoder->encode( $old ); |
114
|
31
|
|
|
|
|
148
|
$new = $encoder->encode( $new ); |
115
|
|
|
|
|
|
|
|
116
|
31
|
100
|
|
|
|
99
|
return 0 if $new eq $old; |
117
|
23
|
|
|
|
|
77
|
return 1; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
__END__ |