| 1 | package Mojolicious::Plugin::Fondation::Action::Controllers; | ||||||||||||||||||||||||||||
| 2 | 15 | $Mojolicious::Plugin::Fondation::Action::Controllers::VERSION = '0.08'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Auto-discovers controller classes under a plugin namespace | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use Mojo::Base 'Mojolicious::Plugin::Fondation::Action::Base', -signatures; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use Mojo::Loader 'find_modules'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 162 | ▶ | sub after_load ($self, $long_name, $conf, $share_dir) { | ||||||||||||||||||||||||||
|
Subroutine
after_load: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | 162 | my $manager = $self->manager; | |||||||||||||||||||||||||||
| 11 | 162 | my $app = $manager->app; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 162 | my $plugin_entry = $manager->registry->{$long_name}; | |||||||||||||||||||||||||||
| 14 | 162 | ▶ | return unless $plugin_entry; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 162 | my $plugin = $plugin_entry->{instance}; | |||||||||||||||||||||||||||
| 17 | 162 | ▶ | return unless $plugin && ref $plugin; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$plugin and ref $plugin
MC/DC0%0/2
$plugin and ref $plugin
$plugin
ref $plugin
Truth table33%1/3
A and B
A= $pluginB= ref $plugin
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 162 | my $short = $plugin_entry->{short_name}; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # Plugin's controller namespace | ||||||||||||||||||||||||||||
| 22 | 162 | my $controller_ns = "${long_name}::Controller"; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # Search for modules in this namespace, excluding base classes | ||||||||||||||||||||||||||||
| 25 | 162 | my @controllers = grep { !/::Base$/ } find_modules($controller_ns); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # Always set metadata for introspection | ||||||||||||||||||||||||||||
| 28 | 162 | $plugin_entry->{metadata}{controllers_count} = scalar @controllers; | |||||||||||||||||||||||||||
| 29 | 162 | $plugin_entry->{metadata}{controllers_ns} = $controller_ns; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 162 | ▶ | return unless @controllers; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # Add namespace to routes (once only) | ||||||||||||||||||||||||||||
| 34 | 125 | my $routes_ns = $app->routes->namespaces; | |||||||||||||||||||||||||||
| 35 | 125 | ▶ | unless (grep { $_ eq $controller_ns } @$routes_ns) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 125 | push @$routes_ns, $controller_ns; | |||||||||||||||||||||||||||
| 37 | 125 | my $count = scalar @controllers; | |||||||||||||||||||||||||||
| 38 | 125 | $self->log->debug("Controller namespace added: $controller_ns ($count controllers)"); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # store the list of controller names | ||||||||||||||||||||||||||||
| 42 | 125 | $plugin_entry->{controllers} = [ sort @controllers ]; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 125 | return $controller_ns; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 15 | 1; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | __END__ | ||||||||||||||||||||||||||||