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