line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Role::MissingMethodUtils; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$MooseX::Role::MissingMethodUtils::VERSION = '0.02'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4370
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub AUTOLOAD |
9
|
|
|
|
|
|
|
{ |
10
|
|
|
|
|
|
|
my ($self, @params) = @_; |
11
|
|
|
|
|
|
|
my ($name) = our $AUTOLOAD =~ /::(\w+)$/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $meth_ref = $self->can('method_missing'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
if ( $meth_ref ) |
16
|
|
|
|
|
|
|
{ |
17
|
|
|
|
|
|
|
@_ = ($self, $name, @params); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
goto &{$meth_ref} if $meth_ref; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
return; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub can |
26
|
|
|
|
|
|
|
{ |
27
|
|
|
|
|
|
|
my ($self, $method) = @_; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $meth_ref = $self->SUPER::can( $method ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
return $meth_ref if $meth_ref; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
if ( $self->can("responds_to") ) |
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
if ( my $meth_ref = $self->responds_to($method) ) |
36
|
|
|
|
|
|
|
{ |
37
|
|
|
|
|
|
|
no strict 'refs'; |
38
|
|
|
|
|
|
|
return *{ $method } = $meth_ref; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# ABSTRACT: Getting rid of boilerplate AUTOLOAD stuff |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |
51
|
|
|
|
|
|
|
=pod |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
MooseX::Role::MissingMethodUtils - Getting rid of boilerplate AUTOLOAD stuff |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 VERSION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
version 0.02 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
package Foo; |
64
|
|
|
|
|
|
|
use Moose; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
with 'MooseX::Role::MissingMethodUtils'; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub method_missing { |
69
|
|
|
|
|
|
|
my ($self, $method_name, @params) = @_; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
if ( $method_name eq 'do_this' ) { |
72
|
|
|
|
|
|
|
Delegator->do_this; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub responds_to { |
77
|
|
|
|
|
|
|
my ($self, $method_name) = @_; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
if ( $method_name =~ /foo/ ) |
80
|
|
|
|
|
|
|
{ |
81
|
|
|
|
|
|
|
return sub { |
82
|
|
|
|
|
|
|
print "Bar"; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 DESCRIPTION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This role will now introduce a method named method_missing. This method is called via AUTOLOAD as a last |
90
|
|
|
|
|
|
|
resort in the calling chain. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Three parameters will be passed in to help with delegation: ref to self,method name, and parameters. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 CALLBACKS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 method_missing |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Call back method that is called during the AUTOLOAD phase. It's unable to find |
99
|
|
|
|
|
|
|
a method and will call this method_missing as last resort for delegation. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 responds_to |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Call back method that is called during a "can" call. This method needs to just |
104
|
|
|
|
|
|
|
return a sub ref. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 METHODS |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 AUTOLOAD |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Just does all the boilerplate autoloading stuff. Will call "method_missing" |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 can |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
A subclass of can, will call "responds_to" if nothing is found in super. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Logan Bell <loganbell@gmail.com> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This software is Copyright (c) 2011 by Logan Bell. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This is free software, licensed under: |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
The (three-clause) BSD License |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|