File Coverage

lib/Mojolicious/Plugin/Fondation/API.pm
Criterion Covered Total %
statement 22 22 100.0
branch 2 2 100.0
condition n/a
subroutine 4 4 100.0
pod 0 2 0.0
total 28 30 93.3


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::Fondation::API;
2             $Mojolicious::Plugin::Fondation::API::VERSION = '0.03';
3             # ABSTRACT: Stable public contract for Fondation plugins -- read-only access
4              
5 13     13   101 use Mojo::Base -base, -signatures;
  13         23  
  13         92  
6              
7             has 'registry';
8              
9             # ---------------------------------------------------------------------------
10             # plugin($name) -- returns a specific plugin's merged config hashref
11             #
12             # $name can be a short name ('Fondation::User') or a long name
13             # ('Mojolicious::Plugin::Fondation::User').
14             # Returns undef if the plugin is not in the registry.
15             # ---------------------------------------------------------------------------
16 6     6 0 1350 sub plugin ($self, $name) {
  6         11  
  6         7  
  6         10  
17 6         17 my $long = $self->_resolve_long($name);
18 6         19 my $entry = $self->registry->{$long};
19 6 100       34 return unless $entry;
20 5         38 return $entry->{config};
21             }
22              
23             # ---------------------------------------------------------------------------
24             # config($name) -- alias for plugin(), returns merged config
25             # ---------------------------------------------------------------------------
26 3     3 0 2070 sub config ($self, $name) {
  3         5  
  3         6  
  3         5  
27 3         11 return $self->plugin($name);
28             }
29              
30             # ---------------------------------------------------------------------------
31             # _resolve_long -- normalizes a name to its long form
32             # ---------------------------------------------------------------------------
33 6     6   9 sub _resolve_long ($self, $name) {
  6         11  
  6         9  
  6         10  
34 6         34 require Mojolicious::Plugin::Fondation::Utils;
35 6         18 return Mojolicious::Plugin::Fondation::Utils::long_name($name);
36             }
37              
38             1;
39              
40             __END__