1Mojolicious::Plugins(3)User Contributed Perl DocumentatioMnojolicious::Plugins(3)
2
3
4
6 Mojolicious::Plugins - Plugins
7
9 use Mojolicious::Plugins;
10
12 Mojolicous::Plugins is the plugin manager of Mojolicious. In your
13 application you will usually use it to load plugins. To implement your
14 own plugins see Mojolicious::Plugin and the "add_hook" method below.
15
17 Mojolicious::Plugins implements the following attributes.
18
19 "hooks"
20 my $hooks = $plugins->hooks;
21 $plugins = $plugins->hooks({foo => [sub {...}]});
22
23 Hash reference containing all hooks that have been registered by loaded
24 plugins.
25
26 "namespaces"
27 my $namespaces = $plugins->namespaces;
28 $plugins = $plugins->namespaces(['Mojolicious::Plugin']);
29
30 Namespaces to load plugins from. You can add more namespaces to load
31 application specific plugins.
32
34 Mojolicious::Plugins inherits all methods from Mojo::Base and
35 implements the following new ones.
36
37 "add_hook"
38 $plugins = $plugins->add_hook(event => sub {...});
39
40 Hook into an event. The following events are available. (Note that
41 "after_*" hooks run in reverse order)
42
43 before_dispatch
44 Runs before the dispatchers determines what action to run. (Passed
45 the default controller instance)
46
47 $plugins->add_hook(before_dispatch => sub {
48 my ($self, $c) = @_;
49 });
50
51 after_dispatch
52 Runs after the dispatchers determines what action to run. (Passed
53 the default controller instance)
54
55 $plugins->add_hook(after_dispatch => sub {
56 my ($self, $c) = @_;
57 });
58
59 after_static_dispatch
60 Runs after the static dispatcher determines if a static file should
61 be served. (Passed the default controller instance)
62
63 $plugins->add_hook(after_static_dispatch => sub {
64 my ($self, $c) = @_;
65 })
66
67 after_build_tx
68 Runs right after the transaction is built and before the HTTP
69 message gets parsed. One usage case would be upload progress bars.
70 (Passed the transaction instance)
71
72 $plugins->add_hook(after_build_tx => sub {
73 my ($self, $tx) = @_;
74 })
75
76 You could also add custom events by using "run_hook" and
77 "run_hook_reverse" in your application.
78
79 "load_plugin"
80 $plugins = $plugins->load_plugin($app, 'something');
81 $plugins = $plugins->load_plugin($app, 'something', foo => 23);
82 $plugins = $plugins->load_plugin($app, 'something', {foo => 23});
83
84 Load a plugin from the configured namespaces and run "register".
85 Optional arguments are passed to register.
86
87 "run_hook"
88 $plugins = $plugins->run_hook('foo');
89 $plugins = $plugins->run_hook(foo => 123);
90
91 Runs a hook.
92
93 "run_hook_reverse"
94 $plugins = $plugins->run_hook_reverse('foo');
95 $plugins = $plugins->run_hook_reverse(foo => 123);
96
97 Runs a hook in reverse order.
98
100 Mojolicious, Mojolicious::Guides, <http://mojolicious.org>.
101
102
103
104perl v5.12.3 2010-08-12 Mojolicious::Plugins(3)