/usr/share/perl5/Mojolicious/Plugins.pm is in libmojolicious-perl 2.23-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | package Mojolicious::Plugins;
use Mojo::Base 'Mojo::EventEmitter';
use Mojo::Util 'camelize';
# "Who would have thought Hell would really exist?
# And that it would be in New Jersey?"
has namespaces => sub { ['Mojolicious::Plugin'] };
# DEPRECATED in Leaf Fluttering In Wind!
sub add_hook {
warn <<EOF;
Mojolicious::Plugins->add_hook is DEPRECATED in favor of
Mojolicious::Plugins->on!
EOF
shift->on(@_);
}
sub emit_hook {
my $self = shift;
$_->(@_) for @{$self->subscribers(shift)};
return $self;
}
# "Everybody's a jerk. You, me, this jerk."
sub emit_hook_reverse {
my $self = shift;
$_->(@_) for reverse @{$self->subscribers(shift)};
return $self;
}
# "Also you have a rectangular object in your colon.
# That's a calculator. I ate it to gain its power."
sub load_plugin {
my ($self, $name) = @_;
# DEPRECATED in Smiling Face With Sunglasses!
my %special = (
ep_render => 'EPRenderer',
epl_renderer => 'EPLRenderer',
i18n => 'I18N',
json_config => 'JSONConfig',
pod_renderer => 'PODRenderer'
);
if (my $new = $special{$name}) {
warn qq/Plugin "$name" is DEPRECATED in favor of "$new"!\n/;
$name = $new;
}
# Try all namspaces
my $class = $name =~ /^[a-z]/ ? camelize($name) : $name;
for my $namespace (@{$self->namespaces}) {
my $module = "${namespace}::$class";
return $module->new if $self->_load($module);
}
# Full module name
return $name->new if $self->_load($name);
# Not found
die qq/Plugin "$name" missing, maybe you need to install it?\n/;
}
sub register_plugin {
my $self = shift;
my $name = shift;
my $app = shift;
$self->load_plugin($name)->register($app, ref $_[0] ? $_[0] : {@_});
}
# DEPRECATED in Leaf Fluttering In Wind!
sub run_hook {
warn <<EOF;
Mojolicious::Plugins->run_hook is DEPRECATED in favor of
Mojolicious::Plugins->emit_hook!
EOF
shift->emit_hook(@_);
}
# DEPRECATED in Leaf Fluttering In Wind!
sub run_hook_reverse {
warn <<EOF;
Mojolicious::Plugins->run_hook_reverse is DEPRECATED in favor of
Mojolicious::Plugins->emit_hook_reverse!
EOF
shift->emit_hook_reverse(@_);
}
sub _load {
my ($self, $module) = @_;
# Load
if (my $e = Mojo::Loader->load($module)) {
die $e if ref $e;
return;
}
# Module is a plugin
return unless $module->isa('Mojolicious::Plugin');
return 1;
}
1;
__END__
=head1 NAME
Mojolicious::Plugins - Plugins
=head1 SYNOPSIS
use Mojolicious::Plugins;
my $plugins = Mojolicious::Plugin->new;
$plugins->load_plugin('Config');
=head1 DESCRIPTION
L<Mojolicious::Plugins> is the plugin manager of L<Mojolicious>.
=head1 ATTRIBUTES
L<Mojolicious::Plugins> implements the following attributes.
=head2 C<namespaces>
my $namespaces = $plugins->namespaces;
$plugins = $plugins->namespaces(['Mojolicious::Plugin']);
Namespaces to load plugins from.
push @{$plugins->namespaces}, 'MyApp::Plugins';
=head1 METHODS
L<Mojolicious::Plugins> inherits all methods from L<Mojo::EventEmitter> and
implements the following new ones.
=head2 C<emit_hook>
$plugins = $plugins->emit_hook('foo');
$plugins = $plugins->emit_hook(foo => 123);
Emit events as hooks.
=head2 C<emit_hook_reverse>
$plugins = $plugins->emit_hook_reverse('foo');
$plugins = $plugins->emit_hook_reverse(foo => 123);
Emit events as hooks in reverse order.
=head2 C<load_plugin>
my $plugin = $plugins->load_plugin('some_thing');
my $plugin = $plugins->load_plugin('SomeThing');
my $plugin = $plugins->load_plugin('MyApp::Plugin::SomeThing');
Load a plugin from the configured namespaces or by full module name.
=head2 C<register_plugin>
$plugins->register_plugin('some_thing', $app);
$plugins->register_plugin('some_thing', $app, foo => 23);
$plugins->register_plugin('some_thing', $app, {foo => 23});
$plugins->register_plugin('SomeThing', $app);
$plugins->register_plugin('SomeThing', $app, foo => 23);
$plugins->register_plugin('SomeThing', $app, {foo => 23});
$plugins->register_plugin('MyApp::Plugin::SomeThing', $app);
$plugins->register_plugin('MyApp::Plugin::SomeThing', $app, foo => 23);
$plugins->register_plugin('MyApp::Plugin::SomeThing', $app, {foo => 23});
Load a plugin from the configured namespaces or by full module name and run
C<register>, optional arguments are passed through.
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
=cut
|