Commit | Line | Data |
---|---|---|
36cf3bcb | 1 | package Tak::ModuleLoader; |
2 | ||
2791fd73 | 3 | use Tak::ModuleLoader::Hook; |
36cf3bcb | 4 | use Moo; |
5 | ||
2791fd73 | 6 | with 'Tak::Role::Service'; |
36cf3bcb | 7 | |
2791fd73 | 8 | has module_sender => (is => 'ro', required => 1); |
9 | ||
10 | has inc_hook => (is => 'lazy'); | |
11 | ||
12 | sub _build_inc_hook { | |
13 | my ($self) = @_; | |
14 | Tak::ModuleLoader::Hook->new(sender => $self->module_sender); | |
15 | } | |
16 | ||
17 | sub handle_enable { | |
799b77f3 | 18 | my ($self) = @_; |
2791fd73 | 19 | push @INC, $self->inc_hook; |
20 | return 'enabled'; | |
36cf3bcb | 21 | } |
22 | ||
2791fd73 | 23 | sub handle_disable { |
24 | my ($self) = @_; | |
25 | my $hook = $self->inc_hook; | |
26 | @INC = grep $_ ne $hook, @INC; | |
27 | return 'disabled'; | |
28 | } | |
29 | ||
30 | sub DEMOLISH { | |
31 | my ($self) = @_; | |
32 | $self->handle_disable; | |
36cf3bcb | 33 | } |
34 | ||
35 | 1; |