line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Module::Manager; |
2
|
3
|
|
|
3
|
|
17
|
use Mojo::Base -base; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
26
|
|
3
|
3
|
|
|
3
|
|
1789
|
use Mojo::Util qw/camelize decamelize/; |
|
3
|
|
|
|
|
143953
|
|
|
3
|
|
|
|
|
348
|
|
4
|
3
|
|
|
3
|
|
2759
|
use YAML; |
|
3
|
|
|
|
|
48686
|
|
|
3
|
|
|
|
|
211
|
|
5
|
3
|
|
|
3
|
|
32
|
use Carp 'croak'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
160
|
|
6
|
3
|
|
|
3
|
|
3945
|
use Module::Load; |
|
3
|
|
|
|
|
3308
|
|
|
3
|
|
|
|
|
20
|
|
7
|
3
|
|
|
3
|
|
1198
|
use FindBin; |
|
3
|
|
|
|
|
1292
|
|
|
3
|
|
|
|
|
1729
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has modules => sub {{}}; |
10
|
|
|
|
|
|
|
has mod_dir => ''; |
11
|
|
|
|
|
|
|
has 'app'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub init { |
14
|
0
|
|
|
0
|
1
|
|
my ($self, $app, $conf) = @_; |
15
|
0
|
|
|
|
|
|
my $path = $app->home; |
16
|
0
|
|
|
|
|
|
my $conf_dir = $conf->{conf_dir}; |
17
|
0
|
|
|
|
|
|
$self->mod_dir($conf->{mod_dir}); |
18
|
0
|
|
|
|
|
|
$self->app($app); |
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
|
open(my $fh, "$path/$conf_dir/application.yaml") or |
21
|
|
|
|
|
|
|
croak "Can't find '$path/$conf_dir/application.yaml'"; |
22
|
0
|
|
|
|
|
|
local $/; |
23
|
0
|
|
|
|
|
|
my ($app_conf) = Load(<$fh>); |
24
|
0
|
|
|
|
|
|
close $fh; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
$self->add($_) for @{ $app_conf->{modules} }; |
|
0
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
0
|
|
|
$app->helper(module => sub { $self }); |
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub add { |
32
|
0
|
|
|
0
|
1
|
|
my ($self, $name, $module) = @_; |
33
|
0
|
0
|
|
|
|
|
croak "Trying to reload module \"$name\"!\n" if exists $self->modules->{$name}; |
34
|
0
|
0
|
|
|
|
|
return $self->modules->{$name} = $module if $module; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $dir = $self->app->home; |
37
|
0
|
|
|
|
|
|
my $path = decamelize $name; |
38
|
0
|
|
|
|
|
|
$path =~ s/-/\//; |
39
|
0
|
|
|
|
|
|
$path = $dir.'/'.$self->mod_dir.'/'.$path; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
@::INC = ("$path/lib", @::INC); |
42
|
0
|
|
|
|
|
|
load $name; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $mod = $name->new; |
45
|
0
|
|
|
|
|
|
$mod->init($self->app, $path); |
46
|
0
|
|
|
|
|
|
$self->modules->{$name} = $mod; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub get { |
50
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
51
|
0
|
0
|
|
|
|
|
return exists $self->modules->{$name} ? $self->modules->{$name} : undef; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |