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