line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::ClassOnlyConstructor; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Make Moo-based object constructors class-only methods |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
15243
|
use Moo::Role (); |
|
2
|
|
|
|
|
25698
|
|
|
2
|
|
|
|
|
44
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
11
|
use constant ROLE_BASE => 'Method::Generate::Constructor::Role::'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
319
|
|
8
|
|
|
|
|
|
|
{ |
9
|
|
|
|
|
|
|
$MooX::ClassOnlyContructor::VERSION = 'v0.1_1'; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# The gist of this code was taken from MooX::StrictConstructor |
13
|
|
|
|
|
|
|
sub import { |
14
|
4
|
|
|
4
|
|
5098
|
my $class = shift; |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
|
|
7
|
my $target = caller; |
17
|
4
|
100
|
66
|
|
|
51
|
die "MooX::ClassOnlyConstructor can only be used on Moo classes." |
18
|
|
|
|
|
|
|
unless $Moo::MAKERS{$target} && $Moo::MAKERS{$target}{is_class}; |
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
|
|
15
|
my $con = Moo->_constructor_maker_for($target); |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
32896
|
my $con_role = ROLE_BASE; |
23
|
3
|
50
|
|
|
|
37
|
if ( $con->can('_generate_constructor') ) { |
24
|
0
|
|
|
|
|
0
|
$con_role .= 'ClassOnlyConstructor'; |
25
|
|
|
|
|
|
|
} else { |
26
|
3
|
|
|
|
|
9
|
$con_role .= 'RetroClassOnlyConstructor'; |
27
|
|
|
|
|
|
|
} |
28
|
3
|
|
|
|
|
20
|
Moo::Role->apply_roles_to_object($con, $con_role); |
29
|
|
|
|
|
|
|
|
30
|
3
|
|
|
|
|
2546
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__END__ |