line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::Role::Parameterized; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$MooX::Role::Parameterized::VERSION = '0.08'; |
4
|
|
|
|
|
|
|
} |
5
|
9
|
|
|
9
|
|
8906823
|
use strict; |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
260
|
|
6
|
9
|
|
|
9
|
|
49
|
use warnings; |
|
9
|
|
|
|
|
28
|
|
|
9
|
|
|
|
|
233
|
|
7
|
9
|
|
|
9
|
|
44
|
use Carp; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
1861
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: MooX::Role::Parameterized - roles with composition parameters |
10
|
9
|
|
|
9
|
|
5380
|
use MooX::Role::Parameterized::Proxy; |
|
9
|
|
|
|
|
1112
|
|
|
9
|
|
|
|
|
301
|
|
11
|
9
|
|
|
9
|
|
95
|
use Exporter qw(import); |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
298
|
|
12
|
9
|
|
|
9
|
|
847
|
use Module::Runtime qw(use_module); |
|
9
|
|
|
|
|
1741
|
|
|
9
|
|
|
|
|
63
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw(role method apply hasp); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %code_for; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
0
|
1
|
0
|
sub hasp { carp "hasp deprecated"; } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub apply { |
20
|
12
|
|
|
12
|
1
|
61161
|
my ( $role, $args, %extra ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
12
|
50
|
|
|
|
65
|
return if !exists $code_for{$role}; |
23
|
|
|
|
|
|
|
|
24
|
12
|
100
|
|
|
|
74
|
$args = [$args] if ref($args) ne ref( [] ); |
25
|
|
|
|
|
|
|
|
26
|
12
|
|
66
|
|
|
93
|
my $target = $extra{target} // caller; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
{ |
29
|
9
|
|
|
9
|
|
1339
|
no strict 'refs'; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
317
|
|
|
12
|
|
|
|
|
213
|
|
30
|
9
|
|
|
9
|
|
48
|
no warnings 'redefine'; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
947
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# necessary for magic |
33
|
12
|
|
|
|
|
68
|
*{ $role . '::hasp' } = sub { |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# carp 'hasp deprecated, use $object->has instead.'; |
36
|
0
|
|
|
0
|
|
0
|
goto &{ $target . '::has' }; |
|
0
|
|
|
|
|
0
|
|
37
|
12
|
|
|
|
|
62
|
}; |
38
|
12
|
|
|
|
|
52
|
*{ $role . '::method' } = sub { |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# carp 'method deprecated, use $object->method instead.'; |
41
|
0
|
|
|
0
|
|
0
|
my ( $name, $code ) = @_; |
42
|
9
|
|
|
9
|
|
49
|
no strict 'refs'; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
1947
|
|
43
|
0
|
|
|
|
|
0
|
*{"$target\::$name"} = $code; |
|
0
|
|
|
|
|
0
|
|
44
|
12
|
|
|
|
|
56
|
}; |
45
|
|
|
|
|
|
|
} |
46
|
12
|
|
|
|
|
196
|
my $p = |
47
|
|
|
|
|
|
|
MooX::Role::Parameterized::Proxy->new( target => $target, role => $role ); |
48
|
12
|
|
|
|
|
28
|
$code_for{$role}->( $_, $p ) foreach ( @{$args} ); |
|
12
|
|
|
|
|
77
|
|
49
|
|
|
|
|
|
|
|
50
|
10
|
|
|
|
|
1929209
|
use_module('Moo::Role')->apply_roles_to_package( $target, $role ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub role(&) { |
54
|
8
|
|
|
8
|
1
|
51729
|
my $package = (caller)[0]; |
55
|
|
|
|
|
|
|
|
56
|
8
|
|
|
|
|
91
|
$code_for{$package} = shift; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
0
|
1
|
|
sub method { carp "hasp deprecated"; } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
__END__ |