| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Mojolicious::Plugins; | 
| 2 | 50 |  |  | 50 |  | 397 | use Mojo::Base 'Mojo::EventEmitter'; | 
|  | 50 |  |  |  |  | 152 |  | 
|  | 50 |  |  |  |  | 393 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 50 |  |  | 50 |  | 437 | use Mojo::Loader qw(load_class); | 
|  | 50 |  |  |  |  | 155 |  | 
|  | 50 |  |  |  |  | 2746 |  | 
| 5 | 50 |  |  | 50 |  | 420 | use Mojo::Util   qw(camelize); | 
|  | 50 |  |  |  |  | 145 |  | 
|  | 50 |  |  |  |  | 39590 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | has namespaces => sub { ['Mojolicious::Plugin'] }; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | sub emit_chain { | 
| 10 | 1636 |  |  | 1636 | 1 | 4699 | my ($self, $name, @args) = @_; | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 1636 |  |  |  |  | 2539 | my $wrapper; | 
| 13 | 1636 |  |  |  |  | 2659 | for my $cb (reverse @{$self->subscribers($name)}) { | 
|  | 1636 |  |  |  |  | 5083 |  | 
| 14 | 2787 |  |  |  |  | 4403 | my $next = $wrapper; | 
| 15 | 2787 |  |  | 2783 |  | 11205 | $wrapper = sub { $cb->($next, @args) }; | 
|  | 2783 |  |  |  |  | 8068 |  | 
| 16 |  |  |  |  |  |  | } | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 1636 | 100 |  |  |  | 5367 | !$wrapper ? return : return $wrapper->(); | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub emit_hook { | 
| 22 | 5008 |  |  | 5008 | 1 | 8852 | my $self = shift; | 
| 23 | 5008 |  |  |  |  | 7799 | for my $cb (@{$self->subscribers(shift)}) { $cb->(@_) } | 
|  | 5008 |  |  |  |  | 14164 |  | 
|  | 623 |  |  |  |  | 2777 |  | 
| 24 | 5008 |  |  |  |  | 11808 | return $self; | 
| 25 |  |  |  |  |  |  | } | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | sub emit_hook_reverse { | 
| 28 | 932 |  |  | 932 | 1 | 1759 | my $self = shift; | 
| 29 | 932 |  |  |  |  | 1559 | for my $cb (reverse @{$self->subscribers(shift)}) { $cb->(@_) } | 
|  | 932 |  |  |  |  | 3463 |  | 
|  | 389 |  |  |  |  | 1123 |  | 
| 30 | 932 |  |  |  |  | 2449 | return $self; | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | sub load_plugin { | 
| 34 | 604 |  |  | 604 | 1 | 1441 | my ($self, $name) = @_; | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | # Try all namespaces and full module name | 
| 37 | 604 | 100 |  |  |  | 2335 | my $suffix  = $name =~ /^[a-z]/ ? camelize $name : $name; | 
| 38 | 604 |  |  |  |  | 1044 | my @classes = map {"${_}::$suffix"} @{$self->namespaces}; | 
|  | 631 |  |  |  |  | 2940 |  | 
|  | 604 |  |  |  |  | 1531 |  | 
| 39 | 604 | 100 |  |  |  | 1523 | for my $class (@classes, $name) { return $class->new if _load($class) } | 
|  | 638 |  |  |  |  | 1448 |  | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | # Not found | 
| 42 | 1 |  |  |  |  | 13 | die qq{Plugin "$name" missing, maybe you need to install it?\n}; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 604 | 100 |  | 604 | 1 | 1919 | sub register_plugin { shift->load_plugin(shift)->register(shift, ref $_[0] ? $_[0] : {@_}) } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub _load { | 
| 48 | 638 |  |  | 638 |  | 1129 | my $module = shift; | 
| 49 | 638 | 100 |  |  |  | 1950 | return $module->isa('Mojolicious::Plugin') unless my $e = load_class $module; | 
| 50 | 35 | 50 |  |  |  | 237 | 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 |