line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::Rebuild; |
2
|
1
|
|
|
1
|
|
9365
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
3
|
1
|
|
|
1
|
|
6
|
use strictures 2; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
41
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
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
|
|
222
|
use Moo::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
35
|
1
|
|
|
1
|
|
859
|
use namespace::clean; |
|
1
|
|
|
|
|
10721
|
|
|
1
|
|
|
|
|
6
|
|
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
|
6607
|
my $self = shift; |
53
|
2
|
|
|
|
|
6
|
my $class = ref( $self ); |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
56
|
my $args = $class->BUILDARGS( @_ ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$args = { |
58
|
2
|
|
|
|
|
5
|
%{ $self->build_args() }, |
|
2
|
|
|
|
|
13
|
|
59
|
|
|
|
|
|
|
%$args, |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
37
|
return $class->new( $args ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
__END__ |