line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::BuildArgs; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$MooX::BuildArgs::VERSION = '0.06'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
MooX::BuildArgs - Save instantiation arguments for later use. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Foo; |
12
|
|
|
|
|
|
|
use Moo; |
13
|
|
|
|
|
|
|
with 'MooX::BuildArgs'; |
14
|
|
|
|
|
|
|
has bar => (is => 'ro'); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $foo = Foo->new( bar => 32 ); |
17
|
|
|
|
|
|
|
print $foo->build_args->{bar}; # 32 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
It is often useful to be able to access the arguments that were |
22
|
|
|
|
|
|
|
used to create an object in their unadulterated form, before any |
23
|
|
|
|
|
|
|
coercions or init_args have changed them. This L role |
24
|
|
|
|
|
|
|
provides the arguments via the L attribute. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Note that no attempt is made to weaken the args. So, if you use |
27
|
|
|
|
|
|
|
this module and you have attributes with C set the |
28
|
|
|
|
|
|
|
references will not be weakened within L. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
2
|
|
10052
|
use Moo::Role; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
11
|
|
33
|
2
|
|
|
2
|
|
1166
|
use strictures 2; |
|
2
|
|
|
|
|
1574
|
|
|
2
|
|
|
|
|
95
|
|
34
|
2
|
|
|
2
|
|
918
|
use namespace::clean; |
|
2
|
|
|
|
|
11395
|
|
|
2
|
|
|
|
|
12
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
with 'MooX::BuildArgsHooks'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
around FINALIZE_BUILDARGS => sub{ |
39
|
|
|
|
|
|
|
my ($orig, $class, $args) = @_; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$args = $class->$orig( $args ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return $class->FINALIZE_BUILD_ARGS_BUILDARGS( $args ); |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub FINALIZE_BUILD_ARGS_BUILDARGS { |
47
|
6
|
|
|
6
|
0
|
13
|
my ($class, $args) = @_; |
48
|
|
|
|
|
|
|
|
49
|
6
|
|
|
|
|
18
|
$args->{_build_args} = { %$args }; |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
|
|
20
|
return $args; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 build_args |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $args_hashref = $object->build_args(); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns a hashref containing the captured arguments. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has build_args => ( |
65
|
|
|
|
|
|
|
is => 'ro', |
66
|
|
|
|
|
|
|
init_arg => '_build_args', |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
__END__ |