| 1 | package IRC::Bot::Auth; | ||||||||||
| 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.02'; | |||||||||
| 14 | |||||||||||
| 15 | 1 | my $cache = new Cache::FileCache( | |||||||||
| 16 | { | ||||||||||
| 17 | 'namespace' => 'BotAuth', | ||||||||||
| 18 | 'default_expires_in' => 3600 | ||||||||||
| 19 | } | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | # Set us up the bomb | ||||||||||
| 23 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | |||||||||||
| 25 | 1 | my $class = shift; | |||||||||
| 26 | 1 | my $self = {}; | |||||||||
| 27 | 1 | return $self, $class; | |||||||||
| 28 | |||||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | # Set authorization Session. | ||||||||||
| 32 | 0 | ▶ | sub auth_set { | ||||||||
|
Subroutine
auth_set: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 33 | |||||||||||
| 34 | 0 | my ( $self, $who ) = @_; | |||||||||
| 35 | |||||||||||
| 36 | 0 | $cache->set( $who, $who ); | |||||||||
| 37 | |||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | # Check for existing Auth Session | ||||||||||
| 41 | 0 | ▶ | sub is_auth { | ||||||||
|
Subroutine
is_auth: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 42 | |||||||||||
| 43 | 0 | my ( $self, $who ) = @_; | |||||||||
| 44 | |||||||||||
| 45 | 0 | my $user = $cache->get($who); | |||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | if ( defined $user ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | return 1; | |||||||||
| 49 | } | ||||||||||
| 50 | else { | ||||||||||
| 51 | 0 | return 0; | |||||||||
| 52 | } | ||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | # If session exists, grab it, and return it. | ||||||||||
| 56 | 0 | ▶ | sub get_ses { | ||||||||
|
Subroutine
get_ses: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 57 | |||||||||||
| 58 | 0 | my ( $self, $who ) = @_; | |||||||||
| 59 | 0 | my $nick = $cache->get($who); | |||||||||
| 60 | 0 | return $nick; | |||||||||
| 61 | |||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | # Break it down now... | ||||||||||
| 65 | 0 | ▶ | sub de_auth { | ||||||||
|
Subroutine
de_auth: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 66 | |||||||||||
| 67 | 0 | my ( $self, $who ) = @_; | |||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | if ( defined $who ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | $cache->clear($who); | |||||||||
| 71 | } | ||||||||||
| 72 | else { | ||||||||||
| 73 | 0 | $cache->clear(); | |||||||||
| 74 | } | ||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | # Blow it to hell. | ||||||||||
| 78 | 0 | ▶ | sub DESTROY { | ||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||
| 79 | |||||||||||
| 80 | 0 | my $self = shift; | |||||||||
| 81 | 0 | $cache->purge(); | |||||||||
| 82 | |||||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 1 | 1; # Goodnight, folks. | |||||||||
| 86 | |||||||||||
| 87 | __END__ | ||||||||||