| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::TeleGramma::PluginManager; | 
| 2 |  |  |  |  |  |  | $App::TeleGramma::PluginManager::VERSION = '0.14'; | 
| 3 |  |  |  |  |  |  | # ABSTRACT: Plugin manager for the TeleGramma bot | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 3 |  |  | 3 |  | 152757 | use Mojo::Base -base; | 
|  | 3 |  |  |  |  | 116569 |  | 
|  | 3 |  |  |  |  | 23 |  | 
| 6 | 3 |  |  | 3 |  | 532 | use File::Spec::Functions qw/catdir/; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 1138 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | require Module::Pluggable; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | has 'config'; | 
| 11 |  |  |  |  |  |  | has 'search_dirs' => sub { [catdir($ENV{HOME}, '.telegramma', 'plugins')] }; | 
| 12 |  |  |  |  |  |  | has 'list' => sub { [] }; | 
| 13 |  |  |  |  |  |  | has 'listeners' => sub { [] }; | 
| 14 |  |  |  |  |  |  | has 'app'; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub load_plugins { | 
| 17 | 2 |  |  | 2 | 0 | 977 | my $self = shift; | 
| 18 | 2 |  |  |  |  | 9 | $self->list([]); | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 2 |  |  |  |  | 22 | Module::Pluggable->import( | 
| 21 |  |  |  |  |  |  | search_path => ['App::TeleGramma::Plugin'], | 
| 22 |  |  |  |  |  |  | search_dirs => $self->search_dirs, | 
| 23 |  |  |  |  |  |  | require     => 1, | 
| 24 |  |  |  |  |  |  | except      => [qw/App::TeleGramma::Plugin::Base/] | 
| 25 |  |  |  |  |  |  | ); | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 2 |  |  |  |  | 196 | foreach my $p ($self->plugins) { | 
| 28 | 12 | 50 |  |  |  | 10232 | if (! $p->check_prereqs()) { | 
| 29 | 0 |  |  |  |  | 0 | warn "$p - failed prereq check\n"; | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | # instantiate it | 
| 33 | 12 |  |  |  |  | 34 | my $o = $p->new(app_config => $self->config, app => $self->app); | 
| 34 | 12 |  |  |  |  | 189 | $o->create_default_config_if_necessary; | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 12 | 100 |  |  |  | 4608 | if ($o->read_config->{enable} =~ /yes/i) { | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | # register it | 
| 39 | 1 |  |  |  |  | 17 | my @botactions = $o->register; | 
| 40 | 1 |  |  |  |  | 4 | foreach my $ba (@botactions) { | 
| 41 | 0 | 0 |  |  |  | 0 | if ($ba->can_listen) { | 
| 42 | 0 |  |  |  |  | 0 | push @{ $self->listeners }, $ba; | 
|  | 0 |  |  |  |  | 0 |  | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | # add it to our list of plugins | 
| 47 | 1 |  |  |  |  | 2 | push @{ $self->list }, $o; | 
|  | 1 |  |  |  |  | 4 |  | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | 1; | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | __END__ | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =pod | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =encoding UTF-8 | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | =head1 NAME | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | App::TeleGramma::PluginManager - Plugin manager for the TeleGramma bot | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | =head1 VERSION | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | version 0.14 | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | =head1 AUTHOR | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | Justin Hawkins <justin@hawkins.id.au> | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | This software is copyright (c) 2019 by Justin Hawkins <justin@eatmorecode.com>. | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 77 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =cut |