| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugins; |
|
2
|
51
|
|
|
51
|
|
478
|
use Mojo::Base 'Mojo::EventEmitter'; |
|
|
51
|
|
|
|
|
163
|
|
|
|
51
|
|
|
|
|
401
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
51
|
|
|
51
|
|
411
|
use Mojo::Loader qw(load_class); |
|
|
51
|
|
|
|
|
164
|
|
|
|
51
|
|
|
|
|
2649
|
|
|
5
|
51
|
|
|
51
|
|
396
|
use Mojo::Util qw(camelize); |
|
|
51
|
|
|
|
|
149
|
|
|
|
51
|
|
|
|
|
40390
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has namespaces => sub { ['Mojolicious::Plugin'] }; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub emit_chain { |
|
10
|
1648
|
|
|
1648
|
1
|
4737
|
my ($self, $name, @args) = @_; |
|
11
|
|
|
|
|
|
|
|
|
12
|
1648
|
|
|
|
|
2557
|
my $wrapper; |
|
13
|
1648
|
|
|
|
|
2448
|
for my $cb (reverse @{$self->subscribers($name)}) { |
|
|
1648
|
|
|
|
|
5275
|
|
|
14
|
2811
|
|
|
|
|
4426
|
my $next = $wrapper; |
|
15
|
2811
|
|
|
2807
|
|
11065
|
$wrapper = sub { $cb->($next, @args) }; |
|
|
2807
|
|
|
|
|
7714
|
|
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
1648
|
100
|
|
|
|
5117
|
!$wrapper ? return : return $wrapper->(); |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub emit_hook { |
|
22
|
5075
|
|
|
5075
|
1
|
8731
|
my $self = shift; |
|
23
|
5075
|
|
|
|
|
7826
|
for my $cb (@{$self->subscribers(shift)}) { $cb->(@_) } |
|
|
5075
|
|
|
|
|
14598
|
|
|
|
623
|
|
|
|
|
2553
|
|
|
24
|
5075
|
|
|
|
|
11958
|
return $self; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub emit_hook_reverse { |
|
28
|
944
|
|
|
944
|
1
|
1768
|
my $self = shift; |
|
29
|
944
|
|
|
|
|
1510
|
for my $cb (reverse @{$self->subscribers(shift)}) { $cb->(@_) } |
|
|
944
|
|
|
|
|
3122
|
|
|
|
389
|
|
|
|
|
1147
|
|
|
30
|
944
|
|
|
|
|
2467
|
return $self; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub load_plugin { |
|
34
|
612
|
|
|
612
|
1
|
1433
|
my ($self, $name) = @_; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Try all namespaces and full module name |
|
37
|
612
|
100
|
|
|
|
2398
|
my $suffix = $name =~ /^[a-z]/ ? camelize $name : $name; |
|
38
|
612
|
|
|
|
|
1015
|
my @classes = map {"${_}::$suffix"} @{$self->namespaces}; |
|
|
639
|
|
|
|
|
2983
|
|
|
|
612
|
|
|
|
|
1692
|
|
|
39
|
612
|
100
|
|
|
|
1532
|
for my $class (@classes, $name) { return $class->new if _load($class) } |
|
|
648
|
|
|
|
|
1384
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Not found |
|
42
|
1
|
|
|
|
|
10
|
die qq{Plugin "$name" missing, maybe you need to install it?\n}; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
612
|
100
|
|
612
|
1
|
1768
|
sub register_plugin { shift->load_plugin(shift)->register(shift, ref $_[0] ? $_[0] : {@_}) } |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _load { |
|
48
|
648
|
|
|
648
|
|
1113
|
my $module = shift; |
|
49
|
648
|
100
|
|
|
|
1949
|
return $module->isa('Mojolicious::Plugin') unless my $e = load_class $module; |
|
50
|
37
|
50
|
|
|
|
221
|
ref $e ? die $e : return undef; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=encoding utf8 |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 NAME |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Mojolicious::Plugins - Plugin manager |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
use Mojolicious::Plugins; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $plugins = Mojolicious::Plugins->new; |
|
66
|
|
|
|
|
|
|
push @{$plugins->namespaces}, 'MyApp::Plugin'; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
L is the plugin manager of L. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 PLUGINS |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
The following plugins are included in the L distribution as examples. |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=over 2 |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item L |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Perl-ish configuration files. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item L |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
General purpose helper collection, loaded automatically. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item L |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Renderer for plain embedded Perl templates, loaded automatically. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item L |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Renderer for more sophisticated embedded Perl templates, loaded automatically. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item L |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Route condition for all kinds of headers, loaded automatically. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item L |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
JSON configuration files. |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item L |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Mount whole L applications. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item L |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
YAML configuration files. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item L |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Template specific helper collection, loaded automatically. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 EVENTS |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
L inherits all events from L. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L implements the following attributes. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 namespaces |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my $namespaces = $plugins->namespaces; |
|
127
|
|
|
|
|
|
|
$plugins = $plugins->namespaces(['Mojolicious::Plugin']); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Namespaces to load plugins from, defaults to L. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Add another namespace to load plugins from |
|
132
|
|
|
|
|
|
|
push @{$plugins->namespaces}, 'MyApp::Plugin'; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 METHODS |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L inherits all methods from L and implements the following new ones. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 emit_chain |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
$plugins->emit_chain('foo'); |
|
141
|
|
|
|
|
|
|
$plugins->emit_chain(foo => 123); |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Emit events as chained hooks. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 emit_hook |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
$plugins = $plugins->emit_hook('foo'); |
|
148
|
|
|
|
|
|
|
$plugins = $plugins->emit_hook(foo => 123); |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Emit events as hooks. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 emit_hook_reverse |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
$plugins = $plugins->emit_hook_reverse('foo'); |
|
155
|
|
|
|
|
|
|
$plugins = $plugins->emit_hook_reverse(foo => 123); |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Emit events as hooks in reverse order. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 load_plugin |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
my $plugin = $plugins->load_plugin('some_thing'); |
|
162
|
|
|
|
|
|
|
my $plugin = $plugins->load_plugin('SomeThing'); |
|
163
|
|
|
|
|
|
|
my $plugin = $plugins->load_plugin('MyApp::Plugin::SomeThing'); |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Load a plugin from the configured namespaces or by full module name. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 register_plugin |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
$plugins->register_plugin('some_thing', Mojolicious->new); |
|
170
|
|
|
|
|
|
|
$plugins->register_plugin('some_thing', Mojolicious->new, foo => 23); |
|
171
|
|
|
|
|
|
|
$plugins->register_plugin('some_thing', Mojolicious->new, {foo => 23}); |
|
172
|
|
|
|
|
|
|
$plugins->register_plugin('SomeThing', Mojolicious->new); |
|
173
|
|
|
|
|
|
|
$plugins->register_plugin('SomeThing', Mojolicious->new, foo => 23); |
|
174
|
|
|
|
|
|
|
$plugins->register_plugin('SomeThing', Mojolicious->new, {foo => 23}); |
|
175
|
|
|
|
|
|
|
$plugins->register_plugin('MyApp::Plugin::SomeThing', Mojolicious->new); |
|
176
|
|
|
|
|
|
|
$plugins->register_plugin( |
|
177
|
|
|
|
|
|
|
'MyApp::Plugin::SomeThing', Mojolicious->new, foo => 23); |
|
178
|
|
|
|
|
|
|
$plugins->register_plugin( |
|
179
|
|
|
|
|
|
|
'MyApp::Plugin::SomeThing', Mojolicious->new, {foo => 23}); |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Load a plugin from the configured namespaces or by full module name and run C, optional arguments are passed |
|
182
|
|
|
|
|
|
|
through. |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
L, L, L. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |