File Coverage

lib/Mojolicious/Plugin/Fondation.pm
Criterion Covered Total %
statement 43 43 100.0
branch n/a
condition 2 2 100.0
subroutine 7 7 100.0
pod 1 1 100.0
total 53 53 100.0


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::Fondation;
2             $Mojolicious::Plugin::Fondation::VERSION = '0.03';
3             # ABSTRACT: Hierarchical plugin loader with configuration priority and resource sharing
4              
5 13     13   2622088 use Mojo::Base 'Mojolicious::Plugin', -signatures;
  13         39  
  13         164  
6 13     13   35907 use Mojolicious::Plugin::Fondation::Resolver;
  13         44  
  13         110  
7 13     13   7047 use Mojolicious::Plugin::Fondation::Manager;
  13         38  
  13         93  
8 13     13   6457 use Mojolicious::Plugin::Fondation::API;
  13         48  
  13         75  
9 13     13   6670 use Mojolicious::Plugin::Fondation::Helpers;
  13         36  
  13         108  
10 13     13   536 use Mojolicious::Plugin::Fondation::Utils qw(merge short_name find_share_dir);
  13         23  
  13         4323  
11              
12 68     68 1 61747 sub register ($self, $app, $config = {}) {
  68         138  
  68         130  
  68         99  
  68         93  
13              
14             my $merged_config = merge(
15             $config,
16 68   100     274 $app->config->{'Fondation'} // {},
17             );
18              
19 68         8310 my $manager = Mojolicious::Plugin::Fondation::Manager->new(
20             app => $app,
21             config => $merged_config,
22             );
23              
24             # API shares the Manager's registry -- no circular ref
25 68         561 $manager->{api} = Mojolicious::Plugin::Fondation::API->new(
26             registry => $manager->registry,
27             );
28              
29             # ── Register all helpers (fallbacks + real) BEFORE plugin discovery ──
30 68         604 Mojolicious::Plugin::Fondation::Helpers->register($app, $manager);
31              
32             # ── Register command namespace ──
33 68         136 push @{$app->commands->namespaces},
  68         234  
34             'Mojolicious::Plugin::Fondation::Command';
35              
36             # ── Resolve the full dependency graph (with cycle detection) ──
37 68         3602 my $resolver = Mojolicious::Plugin::Fondation::Resolver->new(app => $app);
38 68         560 my $sorted = $resolver->resolve('Fondation', $merged_config);
39              
40             # ── Pre-register Fondation itself so load_all skips it ──
41 66         154 my $short = short_name('Mojolicious::Plugin::Fondation');
42 66         193 $manager->registry->{'Mojolicious::Plugin::Fondation'} = {
43             instance => $self,
44             short_name => $short,
45             share_dir => find_share_dir('Mojolicious::Plugin::Fondation'),
46             config => $merged_config,
47             loaded_at => time,
48             metadata => { has_templates => 0, has_assets => 0 },
49             fondation_meta => $resolver->_discover_meta('Mojolicious::Plugin::Fondation'),
50             };
51 66         331 push @{$manager->load_order}, 'Mojolicious::Plugin::Fondation';
  66         176  
52              
53 66         181 $self->{log} = $app->log->context("[$short]");
54              
55             # ── Instantiate all plugins in resolved order ──
56 66         2607 $manager->load_all($sorted);
57              
58             # ── Post-load actions and finalyze ──
59 66         489 $manager->run_post_load_actions();
60              
61 66         2479 $manager->run_finalyze();
62              
63 66         179 $app->plugins->emit_hook(fondation_after_finalyze => $app, $manager);
64              
65 66         1252 $manager->log->info("=== Fondation loaded successfully ===");
66              
67 66         769 $app->routes->get('/')->to(
68             controller => 'Welcome',
69             action => 'index'
70             );
71              
72 66         15930 return $self;
73             }
74              
75             1;
76              
77             __END__