line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::Role::Parameterized::Proxy; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$MooX::Role::Parameterized::Proxy::VERSION = '0.08'; |
4
|
|
|
|
|
|
|
} |
5
|
9
|
|
|
9
|
|
107
|
use strict; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
237
|
|
6
|
9
|
|
|
9
|
|
95
|
use warnings; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
241
|
|
7
|
9
|
|
|
9
|
|
45
|
use Carp qw(croak); |
|
9
|
|
|
|
|
65
|
|
|
9
|
|
|
|
|
4248
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: small proxy to offer mop methods like has, with, requires, etc. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
L is a proxy to the target class. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This proxy offer has, with, before, around, after, requires and method - to avoid inject magic around the L |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
12
|
|
|
12
|
0
|
50
|
my ( $klass, %args ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
12
|
|
|
|
|
79
|
return bless { target => $args{target}, role => $args{role} }, $klass; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub has { |
26
|
14
|
|
|
14
|
0
|
110
|
my $self = shift; |
27
|
14
|
|
|
|
|
25
|
goto &{ $self->{target} . '::has' }; |
|
14
|
|
|
|
|
143
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub with { |
31
|
3
|
|
|
3
|
0
|
18
|
my $self = shift; |
32
|
3
|
|
|
|
|
4
|
goto &{ $self->{target} . '::with' }; |
|
3
|
|
|
|
|
19
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub before { |
36
|
1
|
|
|
1
|
0
|
9
|
my $self = shift; |
37
|
1
|
|
|
|
|
2
|
goto &{ $self->{target} . '::before' }; |
|
1
|
|
|
|
|
6
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub around { |
41
|
1
|
|
|
1
|
0
|
10
|
my $self = shift; |
42
|
1
|
|
|
|
|
2
|
goto &{ $self->{target} . '::around' }; |
|
1
|
|
|
|
|
6
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub after { |
47
|
1
|
|
|
1
|
0
|
9
|
my $self = shift; |
48
|
1
|
|
|
|
|
3
|
goto &{ $self->{target} . '::after' }; |
|
1
|
|
|
|
|
7
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub requires { |
52
|
7
|
|
|
7
|
0
|
1534
|
my $self = shift; |
53
|
7
|
|
|
|
|
18
|
my $target = $self->{target}; |
54
|
7
|
|
|
|
|
13
|
my $role = $self->{role}; |
55
|
|
|
|
|
|
|
|
56
|
7
|
50
|
|
|
|
64
|
if ( $target->can('requires') ) { |
57
|
0
|
|
|
|
|
0
|
goto &{"${target}::requires"}; |
|
0
|
|
|
|
|
0
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
7
|
|
|
|
|
15
|
my $required_method = shift; |
61
|
7
|
100
|
|
|
|
101
|
croak "Can't apply $role to $target - missing $required_method" |
62
|
|
|
|
|
|
|
if !$target->can($required_method); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub method { |
67
|
14
|
|
|
14
|
0
|
58487
|
my ( $self, $name, $code ) = @_; |
68
|
14
|
|
|
|
|
38
|
my $target = $self->{target}; |
69
|
|
|
|
|
|
|
|
70
|
14
|
50
|
|
|
|
155
|
carp("method ${target}\:\:${name} already exists, overriding...") |
71
|
|
|
|
|
|
|
if $target->can($name); |
72
|
|
|
|
|
|
|
|
73
|
9
|
|
|
9
|
|
53
|
no strict 'refs'; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
669
|
|
74
|
14
|
|
|
|
|
26
|
*{"${target}\:\:${name}"} = $code; |
|
14
|
|
|
|
|
83
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |