line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fey::Role::SQL::Cloneable; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
17962
|
use strict; |
|
27
|
|
|
|
|
57
|
|
|
27
|
|
|
|
|
1149
|
|
4
|
27
|
|
|
27
|
|
142
|
use warnings; |
|
27
|
|
|
|
|
39
|
|
|
27
|
|
|
|
|
1134
|
|
5
|
27
|
|
|
27
|
|
125
|
use namespace::autoclean; |
|
27
|
|
|
|
|
45
|
|
|
27
|
|
|
|
|
222
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.43'; |
8
|
|
|
|
|
|
|
|
9
|
27
|
|
|
27
|
|
2455
|
use MooseX::Role::Parameterized 1.00; |
|
27
|
|
|
|
|
802
|
|
|
27
|
|
|
|
|
194
|
|
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
|
|
98
|
my $self = shift; |
|
|
|
|
8
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
8
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
8
|
|
|
|
|
25
|
my $clone = bless { %{$self} }, ref $self; |
|
8
|
|
|
|
|
81
|
|
44
|
|
|
|
|
|
|
|
45
|
8
|
|
|
|
|
30
|
for my $name (@array_attr) { |
46
|
26
|
|
|
|
|
32
|
$clone->{$name} = [ @{ $self->{$name} } ]; |
|
26
|
|
|
|
|
73
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
8
|
|
|
|
|
24
|
for my $name (@hash_attr) { |
50
|
2
|
|
|
|
|
4
|
$clone->{$name} = { %{ $self->{$name} } }; |
|
2
|
|
|
|
|
16
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
8
|
|
|
|
|
29
|
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.43 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SYNOPSIS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
use Moose 2.1200; |
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 |