BuildArgs.pm

filter: Statementstmt 100% 11 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 14 / 14 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« BuildArgs/Meta/ToRole.pm ↑ Summary BuildArgs/Meta/Object.pm »
1 package MooseX::BuildArgs;
2 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 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 ▶use Moose ();
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 2 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 2 1;
49 __END__
« BuildArgs/Meta/ToRole.pm ↑ Summary BuildArgs/Meta/Object.pm »