line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Pluggable; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27233
|
use 5.008006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
45
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
5
|
1
|
|
|
1
|
|
16
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
5
|
use vars qw($AUTOLOAD); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
7
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
142
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.022'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub add_plugin { |
12
|
3
|
|
|
3
|
1
|
44
|
my ($self, $plugin) = @_; |
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
|
|
4
|
push @{$self->_get_plugins()}, $plugin; |
|
3
|
|
|
|
|
12
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
{ |
17
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1114
|
|
|
3
|
|
|
|
|
5
|
|
18
|
3
|
|
|
|
|
26
|
s/^&//, *{"$_"} = \&{"${plugin}::$_"} |
|
8
|
|
|
|
|
47
|
|
|
8
|
|
|
|
|
22
|
|
19
|
3
|
|
|
|
|
4
|
foreach @{"${plugin}::EXPORT_AS_PLUGIN"}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _get_plugins { |
25
|
7
|
|
|
7
|
|
11
|
my $self = shift; |
26
|
|
|
|
|
|
|
|
27
|
7
|
50
|
|
|
|
21
|
if (not ref $self) { |
28
|
0
|
|
|
|
|
0
|
printf " !! ref = %s\n", $self; |
29
|
0
|
|
|
|
|
0
|
croak("Cannot handle the plugins as Class method."); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
7
|
100
|
|
|
|
33
|
$self->{_PLUGINS} = [] if not $self->{_PLUGINS}; |
33
|
7
|
|
|
|
|
36
|
return $self->{_PLUGINS}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub get_plugins { |
38
|
4
|
|
|
4
|
1
|
14
|
return @{$_[0]->_get_plugins()}; |
|
4
|
|
|
|
|
28
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub add_hook { |
43
|
1
|
|
|
1
|
1
|
3
|
my ($self, $hook, $method) = @_; |
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
|
|
|
2
|
if (defined ${$self->{_HOOK}}{$hook}) { |
|
1
|
|
|
|
|
7
|
|
46
|
0
|
|
|
|
|
0
|
carp("The hook ($hook) already in used. It will overwrite with new method."); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
2
|
${$self->{_HOOK}}{$hook} = $method; |
|
1
|
|
|
|
|
6
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub run_hook { |
54
|
3
|
|
|
3
|
1
|
6
|
my ($self, $hook) = @_; |
55
|
3
|
|
|
|
|
3
|
my $method = ${$self->{_HOOK}}{$hook}; |
|
3
|
|
|
|
|
8
|
|
56
|
|
|
|
|
|
|
|
57
|
3
|
100
|
|
|
|
10
|
if (not defined $method) { |
58
|
1
|
|
|
|
|
3
|
my $caller = caller(0); |
59
|
1
|
|
|
|
|
177
|
croak("The hook ($hook) $caller called doesn't exists."); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
30
|
$self->execute_all_plugins_method($method); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub remove_hook { |
68
|
0
|
|
|
0
|
1
|
0
|
my ($self, $hook) = @_; |
69
|
0
|
|
|
|
|
0
|
delete ${$self->{_HOOK}}{$hook}; |
|
0
|
|
|
|
|
0
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub execute_plugin_method { |
74
|
5
|
|
|
5
|
1
|
13
|
my ($self, $plugin, $method, @args) = @_; |
75
|
5
|
|
|
|
|
7
|
my $result; |
76
|
|
|
|
|
|
|
|
77
|
5
|
100
|
|
|
|
7
|
if (defined &{"${plugin}::$method"}) { |
|
5
|
|
|
|
|
30
|
|
78
|
|
|
|
|
|
|
# Give $self to make the plugin method looks like object method. |
79
|
|
|
|
|
|
|
{ |
80
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
430
|
|
|
4
|
|
|
|
|
4
|
|
81
|
4
|
|
|
|
|
7
|
$result = &{"${plugin}::$method"}($self, @args); |
|
4
|
|
|
|
|
16
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
5
|
|
|
|
|
37
|
return $result; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub execute_all_plugins_method { |
88
|
2
|
|
|
2
|
0
|
5
|
my ($self, $method, @args) = @_; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$self->execute_plugin_method($_, $method, @args) |
91
|
2
|
|
|
|
|
6
|
foreach $self->get_plugins(); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
## Deprecated Methods. |
97
|
0
|
|
|
0
|
0
|
|
sub addPlugin { carp("deprecated method."); (shift)->add_plugin(@_) } |
|
0
|
|
|
|
|
|
|
98
|
0
|
|
|
0
|
|
|
sub _getPlugins { carp("deprecated method."); (shift)->_get_plugins(@_) } |
|
0
|
|
|
|
|
|
|
99
|
0
|
|
|
0
|
0
|
|
sub getPlugins { carp("deprecated method."); (shift)->get_plugins(@_) } |
|
0
|
|
|
|
|
|
|
100
|
0
|
|
|
0
|
0
|
|
sub addHook { carp("deprecated method."); (shift)->add_hook(@_) } |
|
0
|
|
|
|
|
|
|
101
|
0
|
|
|
0
|
0
|
|
sub runHook { carp("deprecated method."); (shift)->run_hook(@_) } |
|
0
|
|
|
|
|
|
|
102
|
0
|
|
|
0
|
0
|
|
sub removeHook { carp("deprecated method."); (shift)->remove_hook(@_) } |
|
0
|
|
|
|
|
|
|
103
|
0
|
|
|
0
|
0
|
|
sub executePluginMethod { carp("deprecated method."); (shift)->execute_plugin_method(@_) } |
|
0
|
|
|
|
|
|
|
104
|
0
|
|
|
0
|
0
|
|
sub executeAllPluginsMethod { carp("deprecated method."); (shift)->execute_all_plugins_method(@_) } |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
__END__ |