line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::Role::Parameterized::Proxy; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$MooX::Role::Parameterized::Proxy::VERSION = '0.081'; |
4
|
|
|
|
|
|
|
} |
5
|
9
|
|
|
9
|
|
46
|
use strict; |
|
9
|
|
|
|
|
42
|
|
|
9
|
|
|
|
|
295
|
|
6
|
9
|
|
|
9
|
|
47
|
use warnings; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
231
|
|
7
|
9
|
|
|
9
|
|
41
|
use Carp qw(croak); |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
4163
|
|
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
|
48
|
my ( $klass, %args ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
12
|
|
|
|
|
80
|
return bless { target => $args{target}, role => $args{role} }, $klass; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub has { |
26
|
14
|
|
|
14
|
0
|
102
|
my $self = shift; |
27
|
14
|
|
|
|
|
24
|
goto &{ $self->{target} . '::has' }; |
|
14
|
|
|
|
|
170
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub with { |
31
|
3
|
|
|
3
|
0
|
22
|
my $self = shift; |
32
|
3
|
|
|
|
|
6
|
goto &{ $self->{target} . '::with' }; |
|
3
|
|
|
|
|
24
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub before { |
36
|
1
|
|
|
1
|
0
|
13
|
my $self = shift; |
37
|
1
|
|
|
|
|
3
|
goto &{ $self->{target} . '::before' }; |
|
1
|
|
|
|
|
10
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub around { |
41
|
1
|
|
|
1
|
0
|
9
|
my $self = shift; |
42
|
1
|
|
|
|
|
2
|
goto &{ $self->{target} . '::around' }; |
|
1
|
|
|
|
|
6
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub after { |
47
|
1
|
|
|
1
|
0
|
8
|
my $self = shift; |
48
|
1
|
|
|
|
|
1
|
goto &{ $self->{target} . '::after' }; |
|
1
|
|
|
|
|
6
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub requires { |
52
|
7
|
|
|
7
|
0
|
2054
|
my $self = shift; |
53
|
7
|
|
|
|
|
17
|
my $target = $self->{target}; |
54
|
7
|
|
|
|
|
16
|
my $role = $self->{role}; |
55
|
|
|
|
|
|
|
|
56
|
7
|
50
|
|
|
|
60
|
if ( $target->can('requires') ) { |
57
|
0
|
|
|
|
|
0
|
goto &{"${target}::requires"}; |
|
0
|
|
|
|
|
0
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
7
|
|
|
|
|
18
|
my $required_method = shift; |
61
|
7
|
100
|
|
|
|
94
|
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
|
55520
|
my ( $self, $name, $code ) = @_; |
68
|
14
|
|
|
|
|
37
|
my $target = $self->{target}; |
69
|
|
|
|
|
|
|
|
70
|
14
|
50
|
|
|
|
154
|
carp("method ${target}\:\:${name} already exists, overriding...") |
71
|
|
|
|
|
|
|
if $target->can($name); |
72
|
|
|
|
|
|
|
|
73
|
9
|
|
|
9
|
|
57
|
no strict 'refs'; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
690
|
|
74
|
14
|
|
|
|
|
27
|
*{"${target}\:\:${name}"} = $code; |
|
14
|
|
|
|
|
89
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |