line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fey::Role::SQL::Cloneable; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
17368
|
use strict; |
|
27
|
|
|
|
|
56
|
|
|
27
|
|
|
|
|
1121
|
|
4
|
27
|
|
|
27
|
|
135
|
use warnings; |
|
27
|
|
|
|
|
41
|
|
|
27
|
|
|
|
|
796
|
|
5
|
27
|
|
|
27
|
|
127
|
use namespace::autoclean; |
|
27
|
|
|
|
|
41
|
|
|
27
|
|
|
|
|
211
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.42'; |
8
|
|
|
|
|
|
|
|
9
|
27
|
|
|
27
|
|
2331
|
use MooseX::Role::Parameterized 0.04; |
|
27
|
|
|
|
|
844
|
|
|
27
|
|
|
|
|
187
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
parameter 'real_class' => ( isa => 'Moose::Meta::Class' ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Yeah, I could've used MooseX::Clone, but avoiding the meta-API at |
14
|
|
|
|
|
|
|
# runtime makes this all much faster. Of course, it's probably the |
15
|
|
|
|
|
|
|
# root of all evil. OTOH, it's encapsulated in a role, so we can |
16
|
|
|
|
|
|
|
# always replace it with an actual use of MX::Clone easily enough. |
17
|
|
|
|
|
|
|
role { |
18
|
|
|
|
|
|
|
my $p = shift; |
19
|
|
|
|
|
|
|
my %extra = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my @array_attr; |
22
|
|
|
|
|
|
|
my @hash_attr; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# XXX - hack to allow Fey::Role::SetOperation to get Cloneable |
25
|
|
|
|
|
|
|
# applied to the real consuming class. |
26
|
|
|
|
|
|
|
my $meta = $p->real_class() ? $p->real_class() : $extra{consumer}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
for my $attr ( grep { $_->has_type_constraint() } |
29
|
|
|
|
|
|
|
$meta->get_all_attributes() ) { |
30
|
|
|
|
|
|
|
my $type = $attr->type_constraint(); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
if ( $type->is_a_type_of('ArrayRef') ) { |
33
|
|
|
|
|
|
|
push @array_attr, $attr->name(); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
elsif ( $type->is_a_type_of('HashRef') ) { |
36
|
|
|
|
|
|
|
push @hash_attr, $attr->name(); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
method clone => sub { |
41
|
8
|
|
|
8
|
|
57
|
my $self = shift; |
|
|
|
|
8
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
8
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
8
|
|
|
|
|
16
|
my $clone = bless { %{$self} }, ref $self; |
|
8
|
|
|
|
|
67
|
|
44
|
|
|
|
|
|
|
|
45
|
8
|
|
|
|
|
24
|
for my $name (@array_attr) { |
46
|
26
|
|
|
|
|
21
|
$clone->{$name} = [ @{ $self->{$name} } ]; |
|
26
|
|
|
|
|
59
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
8
|
|
|
|
|
22
|
for my $name (@hash_attr) { |
50
|
2
|
|
|
|
|
3
|
$clone->{$name} = { %{ $self->{$name} } }; |
|
2
|
|
|
|
|
8
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
8
|
|
|
|
|
16
|
return $clone; |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# ABSTRACT: Adds a just-deep-enough clone() method to SQL objects |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=pod |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Fey::Role::SQL::Cloneable - Adds a just-deep-enough clone() method to SQL objects |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 VERSION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
version 0.42 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNOPSIS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
use Moose 0.90; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
with 'Fey::Role::SQL::Cloneable'; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Classes which do this role have a C<clone()> method which does a |
82
|
|
|
|
|
|
|
just-deep-enough clone of the object. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 METHODS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This role provides the following methods: |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 $query->clone() |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Returns a new object which is a clone of the original. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 BUGS |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
See L<Fey> for details on how to report bugs. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 AUTHOR |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This software is Copyright (c) 2011 - 2015 by Dave Rolsky. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This is free software, licensed under: |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |