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