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