| 1 | package IRC::Bot::Quote; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Cache::FileCache; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | require Exporter; | |||||||||
| 10 | |||||||||||
| 11 | 1 | @ISA = qw(Exporter AutoLoader); | |||||||||
| 12 | 1 | @EXPORT = qw(); | |||||||||
| 13 | 1 | $VERSION = '0.01'; | |||||||||
| 14 | |||||||||||
| 15 | 1 | my $cache = Cache::FileCache->new( | |||||||||
| 16 | { | ||||||||||
| 17 | 'namespace' => 'BotQuote' | ||||||||||
| 18 | } | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | # Set us up the bomb | ||||||||||
| 22 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 23 | |||||||||||
| 24 | 1 | my $class = shift; | |||||||||
| 25 | 1 | my $self = {}; | |||||||||
| 26 | 1 | return $self, $class; | |||||||||
| 27 | |||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | # Set quote in cache | ||||||||||
| 31 | 0 | ▶ | sub quote_set { | ||||||||
|
Subroutine
quote_set: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 32 | |||||||||||
| 33 | 0 | my ( $self, $who, $quote ) = @_; | |||||||||
| 34 | 0 | $cache->set( $who, $quote ); | |||||||||
| 35 | 0 | return "Saved quote for $who"; | |||||||||
| 36 | |||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | # Check for existing quote, pass it to channel | ||||||||||
| 40 | 0 | ▶ | sub quote_query { | ||||||||
|
Subroutine
quote_query: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 41 | |||||||||||
| 42 | 0 | my ( $self, $who ) = @_; | |||||||||
| 43 | |||||||||||
| 44 | 0 | my $user = $cache->get($who); | |||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | if ( defined $user ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | return "<$who> said: \"$user\""; | |||||||||
| 48 | } | ||||||||||
| 49 | else { | ||||||||||
| 50 | 0 | return "I don't know who $who is."; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | # Forget user i.e. remove from cache | ||||||||||
| 56 | 0 | ▶ | sub quote_forget { | ||||||||
|
Subroutine
quote_forget: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 57 | |||||||||||
| 58 | 0 | my ( $self, $who ) = @_; | |||||||||
| 59 | 0 | my $nick = $cache->clear($who); | |||||||||
| 60 | 0 | return "Forgot $who"; | |||||||||
| 61 | |||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | # Blow it to hell. | ||||||||||
| 65 | 0 | ▶ | sub DESTROY { | ||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||
| 66 | |||||||||||
| 67 | 0 | my $self = shift; | |||||||||
| 68 | 0 | $cache->purge(); | |||||||||
| 69 | |||||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 1 | 1; # Goodnight, folks. | |||||||||
| 73 | |||||||||||
| 74 | __END__ | ||||||||||