line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::BuildArgs; |
2
|
2
|
|
|
2
|
|
898850
|
use 5.008001; |
|
2
|
|
|
|
|
15
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
MooseX::BuildArgs - Save the original constructor arguments for later use. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Create a class that uses this module: |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package MyClass; |
14
|
|
|
|
|
|
|
use Moose; |
15
|
|
|
|
|
|
|
use MooseX::BuildArgs; |
16
|
|
|
|
|
|
|
has foo => ( is=>'ro', isa=>'Str' ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $object = MyClass->new( foo => 32 ); |
19
|
|
|
|
|
|
|
print $object->build_args->{foo}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Sometimes it is very useful to have access to the contructor arguments before builders, |
24
|
|
|
|
|
|
|
defaults, and coercion take affect. This module provides a build_args hashref attribute |
25
|
|
|
|
|
|
|
for all instances of the consuming class. The build_args attribute contains all arguments |
26
|
|
|
|
|
|
|
that were passed to the constructor. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
A contrived case for this module would be for creating a clone of an object, so you could |
29
|
|
|
|
|
|
|
duplicate an object with the following code: |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $obj1 = MyClass->new( foo => 32 ); |
32
|
|
|
|
|
|
|
my $obj2 = MyClass->new( $obj1->build_args() ); |
33
|
|
|
|
|
|
|
print $obj2->foo(); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
2
|
|
572
|
use Moose (); |
|
2
|
|
|
|
|
464198
|
|
|
2
|
|
|
|
|
58
|
|
38
|
2
|
|
|
2
|
|
14
|
use Moose::Exporter; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
14
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Moose::Exporter->setup_import_methods( |
41
|
|
|
|
|
|
|
role_metaroles => { |
42
|
|
|
|
|
|
|
application_to_class => ['MooseX::BuildArgs::Meta::ToClass'], |
43
|
|
|
|
|
|
|
application_to_role => ['MooseX::BuildArgs::Meta::ToRole'], |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
base_class_roles => ['MooseX::BuildArgs::Meta::Object'], |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
__END__ |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 AUTHOR |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Aran Clary Deltac <bluefeet@gmail.com> |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 LICENSE |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
58
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
59
|
|
|
|
|
|
|
|