blib/lib/Bot/BasicBot/Pluggable/Module/Vars.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 74 CC 15 SCAR 52.5
CC
15
Cov
0%
told
240.0
help
2.0
BEGIN
2.0
CRAP 189.9
1 package Bot::BasicBot::Pluggable::Module::Vars;
2 $Bot::BasicBot::Pluggable::Module::Vars::VERSION = '1.11';
3 use base qw(Bot::BasicBot::Pluggable::Module);
4 use warnings;
5 use strict;
6  
7 sub help {
8 return
9 "Change internal module variables. Usage: !set <module> <variable> <value>, !unset <module> <variable>, !vars <module>.";
10 }
11  
12 sub told {
13 my ( $self, $mess ) = @_;
14 my $body = $mess->{body};
15 return 0 unless defined $body;
16 my ( $command, $mod, $var, $value ) = split( /\s+/, $body, 4 );
17 $command = lc($command);
18  
19 return if !$self->authed( $mess->{who} );
20  
21 if ( $command eq "!set" ) {
22 my $module = $self->{Bot}->module($mod);
23 return "No such module '$module'." unless $module;
24 $value = defined($value) ? $value : ''; # wipe if no value.
25 $module->set( "user_$var", $value ) if $var;
26 return "Set.";
27  
28 }
29 elsif ( $command eq "!unset" ) {
30 return "Usage: !unset <module> <variable>." unless $var;
31 my $module = $self->{Bot}->module($mod);
32 return "No such module '$module'." unless $module;
33 $module->unset("user_$var");
34 return "Unset.";
35  
36 }
37 elsif ( $command eq "!vars" ) {
38 return "You must pass a module" unless defined $mod;
39 my $module = $self->bot->module($mod);
40 return "No such module '$mod'." unless $module;
41 my @vars =
42 map { my $mod = $_; $mod =~ s/^user_// ? $mod : () }
43 $module->store_keys( res => ["^user"] );
44 return "$mod has no variables." unless @vars;
45 return "Variables for $mod: "
46 . (
47 join ", ", map { "'$_' => '" . $module->get("user_$_") . "'" } @vars
48 ) . ".";
49 }
50 }
51  
52 1;
53  
54 __END__
55  
56 =head1 NAME
57  
58 Bot::BasicBot::Pluggable::Module::Vars - change internal module variables
59  
60 =head1 VERSION
61  
62 version 1.11
63  
64 =head1 SYNOPSIS
65  
66 Bot modules have variables that they can use to change their behaviour. This
67 module, when loaded, gives people who are logged in and authenticated the
68 ability to change these variables from the IRC interface. The variables
69 that are set are in the object store, and begin "user_", so:
70  
71 !set Module foo bar
72  
73 will set the store key 'user_foo' to 'bar' in the 'Module' module.
74  
75 =head1 IRC USAGE
76  
77 =over 4
78  
79 =item !set <module> <variable> <value>
80  
81 Sets the variable to value in a given module. Module must be loaded.
82  
83 =item !unset <module> <variable>
84  
85 Unsets a variable (deletes it entirely) for the current load of the module.
86  
87 =item !vars <module>
88  
89 Lists the variables and their current values in a module.
90  
91 =back
92  
93 =head1 AUTHOR
94  
95 Mario Domgoergen <mdom@cpan.org>
96  
97 This program is free software; you can redistribute it
98 and/or modify it under the same terms as Perl itself.