| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MooseX::ShortCut::BuildInstance; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JANDREW'; |
|
3
|
1
|
|
|
1
|
|
502307
|
use version 0.77; our $VERSION = version->declare('v1.44.2'); |
|
|
1
|
|
|
|
|
1507
|
|
|
|
1
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
|
|
#~ use lib '../../../../Log-Shiras/lib'; |
|
5
|
|
|
|
|
|
|
#~ use Log::Shiras::Unhide qw( :InternalBuilDInstancE ); |
|
6
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "You uncovered internal logging statements for MooseX::ShortCut::BuildInstance-$VERSION"; |
|
7
|
1
|
|
|
1
|
|
88
|
use 5.010; |
|
|
1
|
|
|
|
|
3
|
|
|
8
|
1
|
|
|
1
|
|
522
|
use utf8; |
|
|
1
|
|
|
|
|
13
|
|
|
|
1
|
|
|
|
|
4
|
|
|
9
|
1
|
|
|
1
|
|
30
|
use Moose 2.1213; |
|
|
1
|
|
|
|
|
16
|
|
|
|
1
|
|
|
|
|
7
|
|
|
10
|
1
|
|
|
1
|
|
4883
|
use Moose::Meta::Class; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
11
|
1
|
|
|
1
|
|
4
|
use MooseX::Types::Moose qw( Bool HashRef ); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
12
|
|
|
12
|
1
|
|
|
1
|
|
3336
|
use Carp qw( cluck confess ); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
66
|
|
|
13
|
1
|
|
|
1
|
|
4
|
use Moose::Util qw( apply_all_roles ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
6
|
|
|
14
|
1
|
|
|
1
|
|
150
|
use Moose::Exporter; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
6
|
|
|
15
|
|
|
|
|
|
|
Moose::Exporter->setup_import_methods( |
|
16
|
|
|
|
|
|
|
as_is => [qw( |
|
17
|
|
|
|
|
|
|
build_instance build_class should_re_use_classes |
|
18
|
|
|
|
|
|
|
set_class_immutability set_args_cloning |
|
19
|
|
|
|
|
|
|
)], |
|
20
|
|
|
|
|
|
|
); |
|
21
|
1
|
|
|
1
|
|
51
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
46
|
|
|
22
|
1
|
|
|
1
|
|
534
|
use Clone 'clone'; |
|
|
1
|
|
|
|
|
2163
|
|
|
|
1
|
|
|
|
|
51
|
|
|
23
|
1
|
|
|
1
|
|
6
|
use lib '../../../lib',; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
6
|
|
|
24
|
1
|
|
|
|
|
6
|
use MooseX::ShortCut::BuildInstance::Types 1.036 qw( |
|
25
|
|
|
|
|
|
|
BuildClassDict |
|
26
|
1
|
|
|
1
|
|
462
|
); |
|
|
1
|
|
|
|
|
35
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#########1 Package Variables 3#########4#########5#########6#########7#########8#########9 |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $anonymous_class_count = 0; |
|
31
|
|
|
|
|
|
|
our $built_classes = {}; |
|
32
|
|
|
|
|
|
|
our $re_use_classes = 0; |
|
33
|
|
|
|
|
|
|
our $make_classes_immutable = 1; |
|
34
|
|
|
|
|
|
|
our $should_clone_args = 1; |
|
35
|
|
|
|
|
|
|
my @init_class_args = qw( |
|
36
|
|
|
|
|
|
|
package |
|
37
|
|
|
|
|
|
|
superclasses |
|
38
|
|
|
|
|
|
|
roles |
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
my @add_class_args = qw( |
|
41
|
|
|
|
|
|
|
add_roles_in_sequence |
|
42
|
|
|
|
|
|
|
add_attributes |
|
43
|
|
|
|
|
|
|
add_methods |
|
44
|
|
|
|
|
|
|
); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#########1 Public Methods 3#########4#########5#########6#########7#########8#########9 |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub build_class{ |
|
49
|
7
|
100
|
|
7
|
1
|
8713
|
my $temp_args = ( ( scalar( @_ ) == 1 ) ? $_[0] : { @_ } ); |
|
50
|
7
|
50
|
|
|
|
159
|
my $args = $should_clone_args ? clone( $temp_args ) : $temp_args; |
|
51
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "Arrived at build_class with args:" . Dumper( $args ); |
|
52
|
7
|
|
|
|
|
13
|
my ( $class_args, $i, $can_build, $warning, @warn_list, $pre_exists ); |
|
53
|
7
|
|
|
|
|
17
|
for my $key ( @init_class_args ){ |
|
54
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "Processing the class argument: $key"; |
|
55
|
21
|
100
|
|
|
|
76
|
if( exists $args->{$key} ){ |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
###InternalBuilDInstancE warn 'Processing the values:' . Dumper( $args->{$key} ); |
|
57
|
11
|
|
|
|
|
22
|
$class_args->{$key} = $args->{$key}; |
|
58
|
11
|
100
|
|
|
|
27
|
if( $key eq 'package' ){ |
|
59
|
5
|
100
|
|
|
|
21
|
if( $built_classes->{$args->{$key}} ){ |
|
60
|
2
|
|
|
|
|
5
|
$pre_exists = 1; |
|
61
|
2
|
100
|
|
|
|
5
|
if( !$re_use_classes ){ |
|
62
|
1
|
|
|
|
|
4
|
push @warn_list, 'You already built the class: ' . $args->{$key}; |
|
63
|
1
|
|
|
|
|
2
|
$warning = 1; |
|
64
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "unmutablizing the class ..." . Dumper( @warn_list ); |
|
65
|
1
|
|
|
|
|
5
|
$args->{$key}->meta->make_mutable; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
} |
|
68
|
5
|
|
|
|
|
227
|
$built_classes->{$args->{$key}} = 1; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
11
|
|
|
|
|
18
|
delete $args->{$key}; |
|
71
|
|
|
|
|
|
|
}elsif( $key eq 'package' ){ |
|
72
|
2
|
|
|
|
|
8
|
$class_args->{$key} = "ANONYMOUS_SHIRAS_MOOSE_CLASS_" . ++$anonymous_class_count; |
|
73
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "missing a package value - using: " . $class_args->{$key}; |
|
74
|
|
|
|
|
|
|
}elsif( $key eq 'superclasses' ){ |
|
75
|
2
|
|
|
|
|
7
|
$class_args->{$key} = [ 'Anonymous::Shiras::Moose::Class' ], |
|
76
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "missing the superclass value - using: " . Dumper( $class_args->{$key} ); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
7
|
100
|
|
|
|
14
|
if( $warning ){ |
|
80
|
1
|
|
|
|
|
7
|
push @warn_list, 'The old class definitions will be overwritten with args:', Dumper( $class_args ); |
|
81
|
1
|
|
|
|
|
119
|
cluck( join( "\n", @warn_list ) ); |
|
82
|
|
|
|
|
|
|
}else{ |
|
83
|
6
|
|
|
|
|
13
|
my $package_key = $class_args->{package}; |
|
84
|
6
|
|
|
|
|
19
|
$package_key =~ s/::/\//g; |
|
85
|
6
|
|
|
|
|
11
|
$package_key .= '.pm'; |
|
86
|
6
|
100
|
|
|
|
21
|
if( exists $INC{$package_key} ){ |
|
87
|
1
|
50
|
|
|
|
37
|
if( $re_use_classes ){ |
|
88
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "Already built the class: $class_args->{package}"; |
|
89
|
1
|
|
|
|
|
5
|
return $class_args->{package};# Don't rebuild if you are re-using |
|
90
|
|
|
|
|
|
|
} |
|
91
|
0
|
|
|
|
|
0
|
cluck "Overwriting a pre-built and loaded class: " . $class_args->{package} ; |
|
92
|
0
|
|
|
|
|
0
|
$class_args->{package}->meta->make_mutable; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
} |
|
95
|
6
|
|
|
|
|
720
|
my $want_array = ( caller(0) )[5]; |
|
96
|
|
|
|
|
|
|
###InternalBuilDInstancE warn 'class args:' . Dumper( $class_args ); |
|
97
|
|
|
|
|
|
|
###InternalBuilDInstancE warn 'remaining arguments:' . Dumper( $args ); |
|
98
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "want array: $want_array"; |
|
99
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "Pre exists state: " . ($pre_exists//''); |
|
100
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "\$warning state: " . ($warning//''); |
|
101
|
|
|
|
|
|
|
###InternalBuilDInstancE warn 'finalize the class name or load a new one ...'; |
|
102
|
|
|
|
|
|
|
my $class_name = ( $pre_exists and !$warning ) ? |
|
103
|
|
|
|
|
|
|
$class_args->{package} : |
|
104
|
6
|
50
|
66
|
|
|
199
|
Moose::Meta::Class->create( %{$class_args} )->name; |
|
|
6
|
|
|
|
|
52
|
|
|
105
|
|
|
|
|
|
|
###InternalBuilDInstancE warn 'class to this point: ' . $class_name->dump( 2 ); |
|
106
|
6
|
0
|
0
|
|
|
68521
|
if( !$class_name->meta->is_mutable and |
|
|
|
|
33
|
|
|
|
|
|
107
|
|
|
|
|
|
|
( exists $args->{add_attributes} or |
|
108
|
|
|
|
|
|
|
exists $args->{add_methods} or |
|
109
|
|
|
|
|
|
|
exists $args->{add_roles_in_sequence} ) ){ |
|
110
|
|
|
|
|
|
|
###InternalBuilDInstancE warn 'Un-immutablizing the class ...'; |
|
111
|
0
|
|
|
|
|
0
|
$class_name->meta->make_mutable; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
6
|
100
|
|
|
|
94
|
if( exists $args->{add_attributes} ){ |
|
114
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "Found attributes to add"; |
|
115
|
1
|
|
|
|
|
4
|
my $meta = $class_name->meta; |
|
116
|
1
|
|
|
|
|
8
|
for my $attribute ( keys %{$args->{add_attributes}} ){ |
|
|
1
|
|
|
|
|
4
|
|
|
117
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "adding attribute named: $attribute"; |
|
118
|
1
|
|
|
|
|
4
|
$meta->add_attribute( $attribute => $args->{add_attributes}->{$attribute} ); |
|
119
|
|
|
|
|
|
|
} |
|
120
|
1
|
|
|
|
|
4162
|
delete $args->{add_attributes}; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
6
|
100
|
|
|
|
23
|
if( exists $args->{add_methods} ){ |
|
123
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "Found roles to add"; |
|
124
|
4
|
|
|
|
|
12
|
my $meta = $class_name->meta; |
|
125
|
4
|
|
|
|
|
37
|
for my $method ( keys %{$args->{add_methods}} ){ |
|
|
4
|
|
|
|
|
16
|
|
|
126
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "adding method named: $method"; |
|
127
|
5
|
|
|
|
|
69
|
$meta->add_method( $method => $args->{add_methods}->{$method} ); |
|
128
|
|
|
|
|
|
|
} |
|
129
|
4
|
|
|
|
|
127
|
delete $args->{add_methods}; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
6
|
100
|
|
|
|
20
|
if( exists $args->{add_roles_in_sequence} ){ |
|
132
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "Found roles_in_sequence to add"; |
|
133
|
4
|
|
|
|
|
7
|
for my $role ( @{$args->{add_roles_in_sequence}} ){ |
|
|
4
|
|
|
|
|
9
|
|
|
134
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "adding role:" . Dumper( $role ); |
|
135
|
4
|
|
|
|
|
24
|
apply_all_roles( $class_name, $role ); |
|
136
|
|
|
|
|
|
|
} |
|
137
|
4
|
|
|
|
|
16318
|
delete $args->{add_roles_in_sequence}; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
6
|
50
|
|
|
|
19
|
if( $make_classes_immutable ){ |
|
140
|
|
|
|
|
|
|
###InternalBuilDInstancE warn 'Immutablizing the class ...'; |
|
141
|
6
|
|
|
|
|
20
|
$class_name->meta->make_immutable; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "returning: $class_name"; |
|
144
|
6
|
|
|
|
|
1458
|
return $class_name; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub build_instance{ |
|
148
|
3
|
50
|
|
3
|
1
|
3926
|
my $temp_args = is_HashRef( $_[0] ) ? $_[0] : { @_ }; |
|
149
|
3
|
50
|
|
|
|
607
|
my $args = $should_clone_args ? clone( $temp_args ) : $temp_args; |
|
150
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "Arrived at build_instance with args:" . Dumper( $args ); |
|
151
|
3
|
|
|
|
|
6
|
my $class_args; |
|
152
|
3
|
|
|
|
|
8
|
for my $key ( @init_class_args, @add_class_args ){ |
|
153
|
18
|
100
|
|
|
|
30
|
if( exists $args->{$key} ){ |
|
154
|
8
|
|
|
|
|
9
|
$class_args->{$key} = $args->{$key}; |
|
155
|
8
|
|
|
|
|
9
|
delete $args->{$key}; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
###InternalBuilDInstancE warn 'Reduced arguments:' . Dumper( $args ); |
|
159
|
|
|
|
|
|
|
###InternalBuilDInstancE warn 'Class building arguments:' . Dumper( $class_args ); |
|
160
|
3
|
|
|
|
|
8
|
my $class = build_class( $class_args ); |
|
161
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "Built class -$class- To get instance now applying args:" . Dumper( $args ); |
|
162
|
3
|
|
|
|
|
5
|
my $instance; |
|
163
|
3
|
|
|
|
|
154
|
eval '$instance = $class->new( %$args )'; |
|
164
|
3
|
50
|
|
|
|
17
|
if( $@ ){ |
|
165
|
0
|
|
|
|
|
0
|
my $message = $@; |
|
166
|
0
|
0
|
|
|
|
0
|
if( ref $message ){ |
|
167
|
0
|
0
|
|
|
|
0
|
if( $message->can( 'as_string' ) ){ |
|
|
|
0
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
0
|
$message = $message->as_string; |
|
169
|
|
|
|
|
|
|
}elsif( $message->can( 'message' ) ){ |
|
170
|
0
|
|
|
|
|
0
|
$message = $message->message; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
} |
|
173
|
0
|
|
|
|
|
0
|
$message =~ s/\)\n;/\);/g; |
|
174
|
0
|
|
|
|
|
0
|
cluck $message; |
|
175
|
|
|
|
|
|
|
}else{ |
|
176
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "Built instance:" . Dumper( $instance ); |
|
177
|
3
|
|
|
|
|
47
|
return $instance; |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub should_re_use_classes{ |
|
182
|
1
|
|
|
1
|
1
|
1750
|
my ( $bool, ) = @_; |
|
183
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "setting \$re_use_classes to: $bool"; |
|
184
|
1
|
50
|
|
|
|
6
|
$re_use_classes = ( $bool ) ? 1 : 0 ; |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub set_class_immutability{ |
|
188
|
0
|
|
|
0
|
1
|
|
my ( $bool, ) = @_; |
|
189
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "setting \$make_immutable_classes to; $bool"; |
|
190
|
0
|
0
|
|
|
|
|
$make_classes_immutable = ( $bool ) ? 1 : 0 ; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub set_args_cloning{ |
|
194
|
0
|
|
|
0
|
1
|
|
my ( $bool, ) = @_; |
|
195
|
0
|
|
|
|
|
|
$should_clone_args = !!$bool; |
|
196
|
|
|
|
|
|
|
###InternalBuilDInstancE warn "set \$should_clone_args to; $should_clone_args"; |
|
197
|
|
|
|
|
|
|
} |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
#########1 Phinish strong 3#########4#########5#########6#########7#########8#########9 |
|
200
|
|
|
|
|
|
|
|
|
201
|
1
|
|
|
1
|
|
2271
|
no Moose; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
202
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
#########1 Default class 3#########4#########5#########6#########7#########8#########9 |
|
205
|
|
|
|
|
|
|
package Anonymous::Shiras::Moose::Class; |
|
206
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:JANDREW'; |
|
207
|
1
|
|
|
1
|
|
240
|
use Moose; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
5
|
|
|
208
|
1
|
|
|
1
|
|
4540
|
no Moose; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
4
|
|
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
1; |
|
211
|
|
|
|
|
|
|
# The preceding line will help the module return a true value |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
#########1 main pod docs 3#########4#########5#########6#########7#########8#########9 |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
__END__ |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head1 NAME |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
MooseX::ShortCut::BuildInstance - A shortcut to build Moose instances |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=begin html |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
<a href="https://www.perl.org"> |
|
224
|
|
|
|
|
|
|
<img src="https://img.shields.io/badge/perl-5.10+-brightgreen.svg" alt="perl version"> |
|
225
|
|
|
|
|
|
|
</a> |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
<a href="https://travis-ci.org/jandrew/MooseX-ShortCut-BuildInstance"> |
|
228
|
|
|
|
|
|
|
<img alt="Build Status" src="https://travis-ci.org/jandrew/MooseX-ShortCut-BuildInstance.png?branch=master" alt='Travis Build'/> |
|
229
|
|
|
|
|
|
|
</a> |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
<a href='https://coveralls.io/github/jandrew/MooseX-ShortCut-BuildInstance?branch=master'> |
|
232
|
|
|
|
|
|
|
<img src='https://coveralls.io/repos/github/jandrew/MooseX-ShortCut-BuildInstance/badge.svg?branch=master' alt='Coverage Status' /> |
|
233
|
|
|
|
|
|
|
</a> |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
<a href='https://github.com/jandrew/MooseX-ShortCut-BuildInstance'> |
|
236
|
|
|
|
|
|
|
<img src="https://img.shields.io/github/tag/jandrew/MooseX-ShortCut-BuildInstance.svg?label=github version" alt="github version"/> |
|
237
|
|
|
|
|
|
|
</a> |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
<a href="https://metacpan.org/pod/MooseX::ShortCut::BuildInstance"> |
|
240
|
|
|
|
|
|
|
<img src="https://badge.fury.io/pl/MooseX-ShortCut-BuildInstance.svg?label=cpan version" alt="CPAN version" height="20"> |
|
241
|
|
|
|
|
|
|
</a> |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
<a href='http://cpants.cpanauthors.org/dist/MooseX-ShortCut-BuildInstance'> |
|
244
|
|
|
|
|
|
|
<img src='http://cpants.cpanauthors.org/dist/MooseX-ShortCut-BuildInstance.png' alt='kwalitee' height="20"/> |
|
245
|
|
|
|
|
|
|
</a> |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=end html |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
#!/user/bin/env perl |
|
252
|
|
|
|
|
|
|
package Mineral; |
|
253
|
|
|
|
|
|
|
use Moose; |
|
254
|
|
|
|
|
|
|
use Types::Standard qw( Enum ); |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
has 'type' =>( |
|
257
|
|
|
|
|
|
|
isa => Enum[qw( Quartz Diamond Basalt Granite )], |
|
258
|
|
|
|
|
|
|
is => 'ro' |
|
259
|
|
|
|
|
|
|
); |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
package Identity; |
|
262
|
|
|
|
|
|
|
use Moose::Role; |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
has 'name' =>( is => 'ro' ); |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
use lib '../../../lib'; |
|
267
|
|
|
|
|
|
|
use MooseX::ShortCut::BuildInstance qw( should_re_use_classes build_instance ); |
|
268
|
|
|
|
|
|
|
should_re_use_classes( 1 );# To reuse build_instance |
|
269
|
|
|
|
|
|
|
use Test::More; |
|
270
|
|
|
|
|
|
|
use Test::Moose; |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
# First build of instance |
|
273
|
|
|
|
|
|
|
my $paco = build_instance( |
|
274
|
|
|
|
|
|
|
package => 'Pet::Rock', |
|
275
|
|
|
|
|
|
|
superclasses =>['Mineral'], |
|
276
|
|
|
|
|
|
|
roles =>['Identity'], |
|
277
|
|
|
|
|
|
|
type => 'Quartz', |
|
278
|
|
|
|
|
|
|
name => 'Paco', |
|
279
|
|
|
|
|
|
|
); |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
does_ok( $paco, 'Identity', 'Check that the ' . $paco->meta->name . ' has an -Identity-' ); |
|
282
|
|
|
|
|
|
|
print'My ' . $paco->meta->name . ' made from -' . $paco->type . '- (a ' . |
|
283
|
|
|
|
|
|
|
( join ', ', $paco->meta->superclasses ) . ') is called -' . $paco->name . "-\n"; |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
# Next instance (If you don't want to call build_instance again) |
|
286
|
|
|
|
|
|
|
my $Fransisco = Pet::Rock->new( |
|
287
|
|
|
|
|
|
|
type => 'Diamond', |
|
288
|
|
|
|
|
|
|
name => 'Fransisco', |
|
289
|
|
|
|
|
|
|
); |
|
290
|
|
|
|
|
|
|
does_ok( $Fransisco, 'Identity', 'Check that the ' . $Fransisco->meta->name . ' has an -Identity-' ); |
|
291
|
|
|
|
|
|
|
print'My ' . $Fransisco->meta->name . ' made from -' . $Fransisco->type . '- (a ' . |
|
292
|
|
|
|
|
|
|
( join ', ', $Fransisco->meta->superclasses ) . ') is called -' . $Fransisco->name . "-\n"; |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
# Another instance (reusing build_instance) |
|
295
|
|
|
|
|
|
|
my $Gonzalo = build_instance( |
|
296
|
|
|
|
|
|
|
package => 'Pet::Rock', |
|
297
|
|
|
|
|
|
|
superclasses =>['Mineral'], |
|
298
|
|
|
|
|
|
|
roles =>['Identity'], |
|
299
|
|
|
|
|
|
|
type => 'Granite', |
|
300
|
|
|
|
|
|
|
name => 'Gonzalo', |
|
301
|
|
|
|
|
|
|
); |
|
302
|
|
|
|
|
|
|
does_ok( $Gonzalo, 'Identity', 'Check that the ' . $Gonzalo->meta->name . ' has an -Identity-' ); |
|
303
|
|
|
|
|
|
|
print'My ' . $Gonzalo->meta->name . ' made from -' . $Gonzalo->type . '- (a ' . |
|
304
|
|
|
|
|
|
|
( join ', ', $Gonzalo->meta->superclasses ) . ') is called -' . $Gonzalo->name . "-\n"; |
|
305
|
|
|
|
|
|
|
done_testing(); |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
############################################################################## |
|
308
|
|
|
|
|
|
|
# Output of SYNOPSIS |
|
309
|
|
|
|
|
|
|
# 01:ok 1 - Check that the Pet::Rock has an -Identity- |
|
310
|
|
|
|
|
|
|
# 02:My Pet::Rock made from -Quartz- (a Mineral) is called -Paco- |
|
311
|
|
|
|
|
|
|
# 01:ok 1 - Check that the Pet::Rock has an -Identity- |
|
312
|
|
|
|
|
|
|
# 02:My Pet::Rock made from -Diamond- (a Mineral) is called -Fransisco- |
|
313
|
|
|
|
|
|
|
# 01:ok 1 - Check that the Pet::Rock has an -Identity- |
|
314
|
|
|
|
|
|
|
# 02:My Pet::Rock made from -Granite- (a Mineral) is called -Gonzalo- |
|
315
|
|
|
|
|
|
|
# 03:1..3 |
|
316
|
|
|
|
|
|
|
############################################################################## |
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
This module is a shortcut to custom build L<Moose> class instances on the fly. |
|
321
|
|
|
|
|
|
|
The goal is to compose unique instances of Moose classes on the fly using a single |
|
322
|
|
|
|
|
|
|
function call with information describing required attributes, methods, inherited |
|
323
|
|
|
|
|
|
|
classes, and roles as well as any desired instance settings. This package will |
|
324
|
|
|
|
|
|
|
check for and fill in any missing pieces as needed so that your call can either be |
|
325
|
|
|
|
|
|
|
complex or very simple. The goal is to provide configurable instance building |
|
326
|
|
|
|
|
|
|
without stringing together a series of Class-E<gt>method( %args ) calls. |
|
327
|
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
The package can also be used as a class factory with the L<should_re_use_classes |
|
329
|
|
|
|
|
|
|
|/$MooseX::ShortCut::BuildInstance::re_use_classes> method. |
|
330
|
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
Even though this is a Moose based class it provides a functional interface. |
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=head1 WARNING(S) |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
Moose (and I think perl 5) can't have two classes with the same name but |
|
336
|
|
|
|
|
|
|
different guts coexisting! This means that if you build a class (package) name |
|
337
|
|
|
|
|
|
|
on the fly while building an instance and then recompose a new class (package) with |
|
338
|
|
|
|
|
|
|
the same name but different functionality (different attributes, methods, inherited |
|
339
|
|
|
|
|
|
|
classes or roles) while composing a new instance on the fly then all calls |
|
340
|
|
|
|
|
|
|
to the old instance will use the new class functionality for execution. (Usually |
|
341
|
|
|
|
|
|
|
causing hard to troubleshoot failures). This is also true if you re-build a |
|
342
|
|
|
|
|
|
|
prebuilt class name inititally installed with 'use'. |
|
343
|
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
MooseX::ShortCut::BuildInstance will warn if you overwrite named classes (packages) |
|
345
|
|
|
|
|
|
|
built on top of another class (package) also built by MooseX::ShortCut::BuildInstance. |
|
346
|
|
|
|
|
|
|
If you are using the 'build_instance' method to generate multiple instances of |
|
347
|
|
|
|
|
|
|
the same class (by 'package' name) with different attribute settings but built |
|
348
|
|
|
|
|
|
|
with the same functionality then you need to understand the purpose of the |
|
349
|
|
|
|
|
|
|
L<$re_use_classes|/$MooseX::ShortCut::BuildInstance::re_use_classes> global variable. |
|
350
|
|
|
|
|
|
|
An alternative to multiple calls straight to 'build_instance' is to call |
|
351
|
|
|
|
|
|
|
L<build_class|/build_class( %args|\%args )> separately and then just call -E<gt>new |
|
352
|
|
|
|
|
|
|
against the resulting class name over and over again. Another alternative is to |
|
353
|
|
|
|
|
|
|
leave the 'package' argument out of 'build_instance' and let this class create a |
|
354
|
|
|
|
|
|
|
unique by-instance anonymous class/package name. |
|
355
|
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
MooseX::ShortCut::BuildInstance will also warn (but not stop you) if you try to |
|
357
|
|
|
|
|
|
|
overwrite a pre-loaded package initially installed with 'use' or 'require'. |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
The Types module in this package uses L<Type::Tiny> which can, in the |
|
360
|
|
|
|
|
|
|
background, use L<Type::Tiny::XS>. While in general this is a good thing you will |
|
361
|
|
|
|
|
|
|
need to make sure that Type::Tiny::XS is version 0.010 or newer since the older |
|
362
|
|
|
|
|
|
|
ones didn't support the 'Optional' method. |
|
363
|
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
This package will clone the passed arguments to L<build_class|/build_class> and |
|
365
|
|
|
|
|
|
|
L<build_instance|/build_instance> since the references are destructivly parsed. |
|
366
|
|
|
|
|
|
|
If that is not what you want then use the method L<set_args_cloning |
|
367
|
|
|
|
|
|
|
|/set_args_cloning( $bool )> to manage the desired process. Where this is likley |
|
368
|
|
|
|
|
|
|
to go south is if your passed arguments contain a deep perl data set or reference |
|
369
|
|
|
|
|
|
|
that you want shared. In this case clone only the bits you want cloned on the |
|
370
|
|
|
|
|
|
|
script side. |
|
371
|
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
=head1 Functions for Export |
|
373
|
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
=head2 build_instance( %args|\%args ) |
|
375
|
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
=over |
|
377
|
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
B<Definition:> This method is used to create a Moose instance on the fly. |
|
379
|
|
|
|
|
|
|
I<It assumes that you do not have the class pre-built and will look for the |
|
380
|
|
|
|
|
|
|
needed information to compose a new class as well.> Basically this passes the |
|
381
|
|
|
|
|
|
|
%args intact to L<build_class|/build_class( %args|\%args )> first. All the |
|
382
|
|
|
|
|
|
|
relevant class building pieces will be used and removed from the args and then |
|
383
|
|
|
|
|
|
|
this method will run $returned_class_name->new( %remaining_args ) with what is |
|
384
|
|
|
|
|
|
|
left. |
|
385
|
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
B<Accepts:> a hash or hashref of arguments. They must include the |
|
387
|
|
|
|
|
|
|
necessary information to build a class. I<(if you already have a class just |
|
388
|
|
|
|
|
|
|
call $class-E<gt>new( %args ); instead of this method!)> This hashref can also |
|
389
|
|
|
|
|
|
|
contain any attribute settings for the instance as well. See |
|
390
|
|
|
|
|
|
|
L<build_class|/build_class( %args|\%args )> for more information. |
|
391
|
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
B<Returns:> This will return a blessed instance of your new class with |
|
393
|
|
|
|
|
|
|
the passed attribute settings implemented. |
|
394
|
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
=back |
|
396
|
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
=head2 build_class( %args|\%args ) |
|
398
|
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
=over |
|
400
|
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
B<Definition:> This function is used to compose a Moose class on the fly. The |
|
402
|
|
|
|
|
|
|
the goal is to allow for as much or as little class definition as you want to be |
|
403
|
|
|
|
|
|
|
provided by one function call. The goal is also to remove as much of the boilerplate |
|
404
|
|
|
|
|
|
|
and logic sequences for class building as possible and let this package handle that. |
|
405
|
|
|
|
|
|
|
The function begins by using the L<Moose::Meta::Class>-E<gt>class(%args) method. |
|
406
|
|
|
|
|
|
|
For this part the function specifically uses the argument callouts 'package', |
|
407
|
|
|
|
|
|
|
'superclasses', and 'roles'. Any necessary missing pieces will be provided. I<Even |
|
408
|
|
|
|
|
|
|
though L<Moose::Meta::Class>-E<gt>class(%args) allows for the package name to be called |
|
409
|
|
|
|
|
|
|
as the first element of an odd numbered list this implementation does not. To define |
|
410
|
|
|
|
|
|
|
a 'package' name it must be set as the value of the 'package' key in the %args.> |
|
411
|
|
|
|
|
|
|
This function then takes the following arguements; 'add_attributes', 'add_methods', |
|
412
|
|
|
|
|
|
|
and 'add_roles_in_sequence' and implements them in that order. The |
|
413
|
|
|
|
|
|
|
implementation of these values is done with L<Moose::Util> 'apply_all_roles' |
|
414
|
|
|
|
|
|
|
and the meta capability in L<Moose>. |
|
415
|
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
B<Accepts:> a hash or hashref of arguments. Six keys are stripped from the hash or |
|
417
|
|
|
|
|
|
|
hash ref of arguments. I<These keys are always used to build the class. They are |
|
418
|
|
|
|
|
|
|
never passed on to %remaining_args.> |
|
419
|
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
=over |
|
421
|
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
B<The first three key-E<gt>value pairs are consumed simultaneously>. They are; |
|
423
|
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
=over |
|
425
|
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
B<package:> This is the name (a string) that the new instance of |
|
427
|
|
|
|
|
|
|
a this class is blessed under. If this key is not provided the package |
|
428
|
|
|
|
|
|
|
will generate a generic name. This will L<overwrite|/WARNING> any class |
|
429
|
|
|
|
|
|
|
built earlier with the same name. |
|
430
|
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
=over |
|
432
|
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
B<accepts:> a string |
|
434
|
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
=back |
|
436
|
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
B<superclasses:> this is intentionally the same key from |
|
438
|
|
|
|
|
|
|
Moose::Meta::Class-E<gt>create. |
|
439
|
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
=over |
|
441
|
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
B<accepts:> a recognizable (by Moose) class name |
|
443
|
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
=back |
|
445
|
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
B<roles:> this is intentionally the same key from Moose::Meta::Class |
|
447
|
|
|
|
|
|
|
-E<gt>create. |
|
448
|
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
=over |
|
450
|
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
B<accepts:> a recognizable (by Moose) class name |
|
452
|
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
=back |
|
454
|
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
=back |
|
456
|
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
B<The second three key-E<gt>value pairs are consumed in the following |
|
458
|
|
|
|
|
|
|
sequence>. They are; |
|
459
|
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
=over |
|
461
|
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
B<add_attributes:> this will add attributes to the class using the |
|
463
|
|
|
|
|
|
|
L<Moose::Meta::Class>-E<gt>add_attribute method. Because these definitions |
|
464
|
|
|
|
|
|
|
are passed as key / value pairs in a hash ref they are not added in |
|
465
|
|
|
|
|
|
|
any specific order. |
|
466
|
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
=over |
|
468
|
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
B<accepts:> a hash ref where the keys are attribute names and the values |
|
470
|
|
|
|
|
|
|
are hash refs of the normal definitions used to define a Moose attribute. |
|
471
|
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
=back |
|
473
|
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
B<add_methods:> this will add methods to the class using the |
|
476
|
|
|
|
|
|
|
L<Moose::Meta::Class>-E<gt>add_method method. Because these definitions |
|
477
|
|
|
|
|
|
|
are passed as key / value pairs in a hash ref they are not added in |
|
478
|
|
|
|
|
|
|
any specific order. |
|
479
|
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
=over |
|
481
|
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
B<accepts:> a hash ref where the keys are method names and the values |
|
483
|
|
|
|
|
|
|
are anonymous subroutines or subroutine references. |
|
484
|
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
=back |
|
486
|
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
B<add_roles_in_sequence:> this will compose, in sequence, each role in |
|
488
|
|
|
|
|
|
|
the array ref into the class built on the prior three arguments using |
|
489
|
|
|
|
|
|
|
L<Moose::Util> apply_all_roles. This will allow an added role to |
|
490
|
|
|
|
|
|
|
'require' elements of a role earlier in the sequence. The roles |
|
491
|
|
|
|
|
|
|
implemented with the L<role|/roles:> key are installed first and in a |
|
492
|
|
|
|
|
|
|
group. Then these roles are installed one at a time. |
|
493
|
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
=over |
|
495
|
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
B<accepts:> an array ref list of roles recognizable (by Moose) as roles |
|
497
|
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
=back |
|
499
|
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
=back |
|
501
|
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
=back |
|
503
|
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
B<Returns:> This will check the caller and see if it wants an array or a |
|
505
|
|
|
|
|
|
|
scalar. In array context it returns the new class name and a hash ref of the |
|
506
|
|
|
|
|
|
|
unused hash key/value pairs. These are presumably the arguments for the |
|
507
|
|
|
|
|
|
|
instance. If the requested return is a scalar it just returns the name of |
|
508
|
|
|
|
|
|
|
the newly created class. |
|
509
|
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
=back |
|
511
|
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
=head2 should_re_use_classes( $bool ) |
|
513
|
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
=over |
|
515
|
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
This sets/changes the global variable |
|
517
|
|
|
|
|
|
|
L<MooseX::ShortCut::BuildInstance::re_use_classes |
|
518
|
|
|
|
|
|
|
|/$MooseX::ShortCut::BuildInstance::re_use_classes> |
|
519
|
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
=back |
|
521
|
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
=head2 set_class_immutability( $bool ) |
|
523
|
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
=over |
|
525
|
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
This sets/changes the global variable |
|
527
|
|
|
|
|
|
|
L<MooseX::ShortCut::BuildInstance::make_classes_immutable |
|
528
|
|
|
|
|
|
|
|/$MooseX::ShortCut::BuildInstance::make_classes_immutable> |
|
529
|
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
=back |
|
531
|
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
=head2 set_args_cloning( $bool ) |
|
533
|
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
=over |
|
535
|
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
This sets/changes the global variable |
|
537
|
|
|
|
|
|
|
L<MooseX::ShortCut::BuildInstance::should_clone_args |
|
538
|
|
|
|
|
|
|
|/$MooseX::ShortCut::BuildInstance::should_clone_args> |
|
539
|
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
=back |
|
541
|
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
=head1 GLOBAL VARIABLES |
|
543
|
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
=head2 $MooseX::ShortCut::BuildInstance::anonymous_class_count |
|
545
|
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
This is an integer that increments and appends to the anonymous package name |
|
547
|
|
|
|
|
|
|
for each new anonymous package (class) created. |
|
548
|
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
=head2 $MooseX::ShortCut::BuildInstance::built_classes |
|
550
|
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
This is a hashref that tracks the class names ('package's) built buy this class |
|
552
|
|
|
|
|
|
|
to manage duplicate build behaviour. |
|
553
|
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
=head2 $MooseX::ShortCut::BuildInstance::re_use_classes |
|
555
|
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
This is a boolean (1|0) variable that tracks if the class should overwrite or |
|
557
|
|
|
|
|
|
|
re-use a package name (and the defined class) from a prior 'build_class' call. |
|
558
|
|
|
|
|
|
|
If the package name is overwritten it will L<cluck|https://metacpan.org/pod/Carp#SYNOPSIS> |
|
559
|
|
|
|
|
|
|
in warning since any changes will affect active instances of prior class builds |
|
560
|
|
|
|
|
|
|
with the same name. If you wish to avoid changing old built behaviour at the risk |
|
561
|
|
|
|
|
|
|
of not installing new behaviour then set this variable to true. I<No warning will |
|
562
|
|
|
|
|
|
|
be provided if new requested class behaviour is discarded.> The class reuse behaviour |
|
563
|
|
|
|
|
|
|
can be changed with the exported method L<should_re_use_classes |
|
564
|
|
|
|
|
|
|
|/should_re_use_classes( $bool )>. This does not apply to pre-loaded classes. |
|
565
|
|
|
|
|
|
|
For pre-loaded classes this package will cluck and then overwrite every time. |
|
566
|
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
=over |
|
568
|
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
B<Default:> False = warn then overwrite |
|
570
|
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
=back |
|
572
|
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
=head2 $MooseX::ShortCut::BuildInstance::make_classes_immutable |
|
574
|
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
This is a boolean (1|0) variable that manages whether a class is immutabilized at the end of |
|
576
|
|
|
|
|
|
|
creation. This can be changed with the exported method L<set_class_immutability |
|
577
|
|
|
|
|
|
|
|/set_class_immutability( $bool )>. |
|
578
|
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
=over |
|
580
|
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
B<Default:> True = always immutabilize classes after building |
|
582
|
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
=back |
|
584
|
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
=head2 $MooseX::ShortCut::BuildInstance::should_clone_args |
|
586
|
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
This is a boolean (1|0) variable that manages whether a the arguments passed to |
|
588
|
|
|
|
|
|
|
L<build_instance|/build_instance( %argsE<verbar>\%args )> and L<build_class |
|
589
|
|
|
|
|
|
|
|/build_class( %argsE<verbar>\%args )> are cloned (using L<Clone> ) the arguments |
|
590
|
|
|
|
|
|
|
to both of these are processed destructivly so generally you would want them cloned |
|
591
|
|
|
|
|
|
|
but not in every case. If you want cloning to be managed on the script side set this |
|
592
|
|
|
|
|
|
|
global variable to 0. Where this is likley to be helpful is if your passed arguments |
|
593
|
|
|
|
|
|
|
contain a deep perl data set or reference that you want shared. In this case clone only |
|
594
|
|
|
|
|
|
|
the bits you want cloned on the script side. |
|
595
|
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
=over |
|
597
|
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
B<Default:> True = always clone arguments |
|
599
|
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
=back |
|
601
|
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
=head1 Build/Install from Source |
|
603
|
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
=over |
|
605
|
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
B<1.> Download a compressed file with the code |
|
607
|
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
B<2.> Extract the code from the compressed file. |
|
609
|
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
=over |
|
611
|
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
If you are using tar this should work: |
|
613
|
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
tar -zxvf Spreadsheet-XLSX-Reader-LibXML-v0.xx.tar.gz |
|
615
|
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
=back |
|
617
|
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
B<3.> Change (cd) into the extracted directory |
|
619
|
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
B<4.> Run the following |
|
621
|
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
=over |
|
623
|
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
(For Windows find what version of make was used to compile your perl) |
|
625
|
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
perl -V:make |
|
627
|
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
(for Windows below substitute the correct make function (s/make/dmake/g)?) |
|
629
|
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
=back |
|
631
|
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
>perl Makefile.PL |
|
633
|
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
>make |
|
635
|
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
>make test |
|
637
|
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
>make install # As sudo/root |
|
639
|
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
>make clean |
|
641
|
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
=back |
|
643
|
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
=head1 SUPPORT |
|
645
|
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
=over |
|
647
|
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
L<MooseX-ShortCut-BuildInstance/issues|https://github.com/jandrew/MooseX-ShortCut-BuildInstance/issues> |
|
649
|
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
=back |
|
651
|
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
=head1 TODO |
|
653
|
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
=over |
|
655
|
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
B<1.> L<Increase test coverage |
|
657
|
|
|
|
|
|
|
|https://coveralls.io/github/jandrew/MooseX-ShortCut-BuildInstance?branch=master> |
|
658
|
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
B<2.> Add an explicit 'export' setup call using L<Moose::Exporter> as an action key in |
|
660
|
|
|
|
|
|
|
'build_class' |
|
661
|
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
=back |
|
663
|
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
=head1 AUTHOR |
|
665
|
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
=over |
|
667
|
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
Jed Lund |
|
669
|
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
jandrew@cpan.org |
|
671
|
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
=back |
|
673
|
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
675
|
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
This program is free software; you can redistribute |
|
677
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
|
678
|
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
The full text of the license can be found in the |
|
680
|
|
|
|
|
|
|
LICENSE file included with this module. |
|
681
|
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
This software is copyrighted (c) 2012, 2016 by Jed Lund |
|
683
|
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
=head1 Dependencies |
|
685
|
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
=over |
|
687
|
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
L<version> |
|
689
|
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
L<5.010|http://perldoc.perl.org/perl5100delta.html> (for use of |
|
691
|
|
|
|
|
|
|
L<defined or|http://perldoc.perl.org/perlop.html#Logical-Defined-Or> //) |
|
692
|
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
L<Moose> |
|
694
|
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
L<Moose::Meta::Class> |
|
696
|
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
L<Carp> - cluck |
|
698
|
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
L<Moose::Exporter> |
|
700
|
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
L<Moose::Util> - apply_all_roles |
|
702
|
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
L<Moose::Exporter> |
|
704
|
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
L<Type::Tiny> - 1.000 |
|
706
|
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
L<Data::Dumper> |
|
708
|
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
L<MooseX::ShortCut::BuildInstance::Types> |
|
710
|
|
|
|
|
|
|
|
|
711
|
|
|
|
|
|
|
=back |
|
712
|
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
714
|
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
=over |
|
716
|
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
L<Moose::Meta::Class> ->create |
|
718
|
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
L<Moose::Util> ->with_traits |
|
720
|
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
L<MooseX::ClassCompositor> |
|
722
|
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
L<Log::Shiras::Unhide> |
|
724
|
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
=over |
|
726
|
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
All debug lines in this module are warn statements and are hidden behind |
|
728
|
|
|
|
|
|
|
'###InternalBuilDInstancE'. When exposed they can be redirected to log files with |
|
729
|
|
|
|
|
|
|
Log::Shiras::TapWarn. |
|
730
|
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
=back |
|
732
|
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
=back |
|
734
|
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
=cut |
|
736
|
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
#########1#########2 main pod documentation end 5#########6#########7#########8#########9 |