-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hooker.pm
61 lines (44 loc) · 1.04 KB
/
Hooker.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package Clone::Hooker;
use MooseX::Role::Parameterized;
parameter copy => (
isa => 'ArrayRef[Str]',
default => sub { [] },
);
parameter reference => (
isa => 'ArrayRef[Str]',
default => sub { [] },
);
role {
my $p = shift;
my @stack;
my @copy = @{$p->copy};
my @reference = @{$p->reference};
method STORABLE_freeze => sub {
my ($self, $cloning) = @_;
die q(you can't freeze this thing silly!) unless $cloning;
my %frame;
for my $ref (@reference) {
$frame{$ref} = $self->$ref
}
push @stack, \%frame;
my %ret;
for my $cop (@copy) {
$ret{$cop} = $self->$cop
}
return \%ret
};
method STORABLE_thaw => sub {
my ($self, $cloning, $ice) = @_;
die q(you can't thaw this thing silly!) unless $cloning;
my %frame = %{pop @stack};
my $new = $self->new({
%$self,
map {
$_ => $frame{$_}
} keys %frame,
});
%$self = %$new;
}
};
no MooseX::Role::Parameterized;
1;