line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::Rebuild; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$MooX::Rebuild::VERSION = '0.06'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
MooX::Rebuild - Rebuild your Moo objects. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Foo; |
12
|
|
|
|
|
|
|
use Moo; |
13
|
|
|
|
|
|
|
with 'MooX::Rebuild'; |
14
|
|
|
|
|
|
|
has get_bar => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
init_arg => 'bar', |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $foo1 = Foo->new( bar => 'lala' ); |
20
|
|
|
|
|
|
|
my $foo2 = $foo1->rebuild(); |
21
|
|
|
|
|
|
|
print $foo2->get_bar(); # lala |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Make copies of Moo objects using the same arguments used to create |
26
|
|
|
|
|
|
|
the original objects. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This Moo role depends on, and uses, the L role in |
29
|
|
|
|
|
|
|
order to capture the original arguments used to create an object. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
9743
|
use Moo::Role; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
34
|
1
|
|
|
1
|
|
818
|
use strictures 2; |
|
1
|
|
|
|
|
1672
|
|
|
1
|
|
|
|
|
41
|
|
35
|
1
|
|
|
1
|
|
650
|
use namespace::clean; |
|
1
|
|
|
|
|
11484
|
|
|
1
|
|
|
|
|
7
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
with 'MooX::BuildArgs'; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 METHODS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 rebuild |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $clone = $object->rebuild(); |
44
|
|
|
|
|
|
|
my $similar = $object->rebuild( %extra_args ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Creates a new instance in the same class as the source object and |
47
|
|
|
|
|
|
|
using the same arguments used to make the source object. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub rebuild { |
52
|
2
|
|
|
2
|
1
|
6666
|
my $self = shift; |
53
|
2
|
|
|
|
|
4
|
my $class = ref( $self ); |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
51
|
my $args = $class->BUILDARGS( @_ ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$args = { |
58
|
2
|
|
|
|
|
4
|
%{ $self->build_args() }, |
|
2
|
|
|
|
|
11
|
|
59
|
|
|
|
|
|
|
%$args, |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
35
|
return $class->new( $args ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
__END__ |