« blib/lib/Bot/BasicBot/Pluggable/Module/Google.pm
↑ Summary
blib/lib/Bot/BasicBot/Pluggable/Module/Karma.pm »
| 1 | package Bot::BasicBot::Pluggable::Module::Loader; | ||||||||||||||||||||||
| 2 | 2 | $Bot::BasicBot::Pluggable::Module::Loader::VERSION = '1.20'; | |||||||||||||||||||||
| 3 | 2 | ▶ | use base qw(Bot::BasicBot::Pluggable::Module); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 2 | ▶ | use Try::Tiny; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | sub init { | ||||||||||||||||||||||
| 9 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||
| 10 | 2 | my @modules = grep !/^user_/, $self->store_keys; | |||||||||||||||||||||
| 11 | 2 | for (@modules) { | |||||||||||||||||||||
| 12 | 0 | ▶ | try { $self->{Bot}->load($_) } catch { warn "Error loading $_: $@." }; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | sub help { | ||||||||||||||||||||||
| 17 | return | ||||||||||||||||||||||
| 18 | 0 | ▶ | "Module loader and unloader. Usage: !load <module>, !unload <module>, !reload <module>, !list."; | ||||||||||||||||||||
|
Subroutine
help: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | sub maybe_join { | ||||||||||||||||||||||
| 22 | 0 | ▶ | my ( $sep, @list ) = @_; | ||||||||||||||||||||
|
Subroutine
maybe_join: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||
| 23 | 0 | ▶ | return $list[0] if @list == 1; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 24 | 0 | ▶ | return join( $sep, @list ) if @list > 1; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 25 | 0 | ▶ | return '' if !@list; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 26 | 0 | return; | |||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||
| 28 | |||||||||||||||||||||||
| 29 | sub told { | ||||||||||||||||||||||
| 30 | 0 | ▶ | my ( $self, $mess ) = @_; | ||||||||||||||||||||
|
Subroutine
told: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||
| 31 | 0 | my $body = $mess->{body}; | |||||||||||||||||||||
| 32 | |||||||||||||||||||||||
| 33 | # we don't care about commands that don't start with '!' | ||||||||||||||||||||||
| 34 | 0 | ▶ | return 0 unless defined $body; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 35 | 0 | ▶ | return 0 unless $body =~ /^!/; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 36 | |||||||||||||||||||||||
| 37 | 0 | ▶ | return if !$self->authed( $mess->{who} ); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 39 | 0 | my ( $command, $param ) = split( /\s+/, $body, 2 ); | |||||||||||||||||||||
| 40 | 0 | $command = lc($command); | |||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | 0 | ▶ | if ( $command eq "!list" ) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 43 | 0 | my %available = map { lc $_ => $_ } $self->bot->available_modules(); | |||||||||||||||||||||
| 44 | 0 | my @loaded = map { delete $available{$_} } @{ $self->bot->handlers() }; | |||||||||||||||||||||
| 45 | 0 | my @available = values %available; | |||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | 0 | my $loaded = maybe_join( ', ', sort @loaded ); | |||||||||||||||||||||
| 48 | 0 | my $available = maybe_join( ', ', sort @available ); | |||||||||||||||||||||
| 49 | 0 | return "Loaded modules: $loaded\nAvailable modules: $available"; | |||||||||||||||||||||
| 50 | |||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||
| 52 | elsif ( $command eq "!load" ) { | ||||||||||||||||||||||
| 53 | 0 | ▶ | try { $self->bot->load($param) } catch { return "Failed: $@." }; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 54 | 0 | $self->set( $param => 1 ); | |||||||||||||||||||||
| 55 | 0 | return "Success."; | |||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||
| 58 | elsif ( $command eq "!reload" ) { | ||||||||||||||||||||||
| 59 | 0 | ▶ | try { $self->bot->reload($param) } catch { return "Failed: $@." }; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 60 | 0 | return "Success."; | |||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||
| 63 | elsif ( $command eq "!unload" ) { | ||||||||||||||||||||||
| 64 | 0 | ▶ | try { $self->bot->unload($param) } catch { return "Failed: $@." }; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 65 | 0 | $self->unset($param); | |||||||||||||||||||||
| 66 | 0 | return "Success."; | |||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||
| 69 | |||||||||||||||||||||||
| 70 | 2 | 1; | |||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||
| 73 | |||||||||||||||||||||||
| 74 | =head1 NAME | ||||||||||||||||||||||
| 75 | |||||||||||||||||||||||
| 76 | Bot::BasicBot::Pluggable::Module::Loader - loads and unloads bot modules; remembers state | ||||||||||||||||||||||
| 77 | |||||||||||||||||||||||
| 78 | =head1 VERSION | ||||||||||||||||||||||
| 79 | |||||||||||||||||||||||
| 80 | version 1.20 | ||||||||||||||||||||||
| 81 | |||||||||||||||||||||||
| 82 | =head1 IRC USAGE | ||||||||||||||||||||||
| 83 | |||||||||||||||||||||||
| 84 | =over 4 | ||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | =item !load <module> | ||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | Loads the named module. | ||||||||||||||||||||||
| 89 | |||||||||||||||||||||||
| 90 | =item !unload <module> | ||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | Unloads the named module. | ||||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | =item !reload <module> | ||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | Reloads a module (combines !unload and !load). | ||||||||||||||||||||||
| 97 | |||||||||||||||||||||||
| 98 | =item !list | ||||||||||||||||||||||
| 99 | |||||||||||||||||||||||
| 100 | Lists all loaded modules. | ||||||||||||||||||||||
| 101 | |||||||||||||||||||||||
| 102 | =back | ||||||||||||||||||||||
| 103 | |||||||||||||||||||||||
| 104 | =head1 AUTHOR | ||||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | Mario Domgoergen <mdom@cpan.org> | ||||||||||||||||||||||
| 107 | |||||||||||||||||||||||
| 108 | This program is free software; you can redistribute it | ||||||||||||||||||||||
| 109 | and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||