| 1 | package IRC::Bot::Log; | ||||||||||
| 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 | |||||||||||
| 8 | 1 | require Exporter; | |||||||||
| 9 | |||||||||||
| 10 | 1 | @ISA = qw(Exporter AutoLoader); | |||||||||
| 11 | 1 | @EXPORT = qw(); | |||||||||
| 12 | 1 | $VERSION = '0.02'; | |||||||||
| 13 | |||||||||||
| 14 | # Set us up the bomb | ||||||||||
| 15 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 16 | |||||||||||
| 17 | 1 | my $class = shift; | |||||||||
| 18 | 1 | my %args = @_; | |||||||||
| 19 | 1 | return bless \%args, $class; | |||||||||
| 20 | |||||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | # Set up a list of Bot names | ||||||||||
| 24 | # For use in other methods | ||||||||||
| 25 | 0 | ▶ | sub _list { | ||||||||
|
Subroutine
_list: not called CC=1 SCAR=6.9
| |||||||||||
| 26 | |||||||||||
| 27 | 0 | my $self = shift; | |||||||||
| 28 | 0 | my $blog = $self->{'Path'} . "bot.log"; | |||||||||
| 29 | 0 | my $slog = $self->{'Path'} . "server.log"; | |||||||||
| 30 | 0 | my $clog = $self->{'Path'} . "channel.log"; | |||||||||
| 31 | 0 | my %list = ( | |||||||||
| 32 | 'Bot' => $blog, | ||||||||||
| 33 | 'Server' => $slog, | ||||||||||
| 34 | 'Channel' => $clog | ||||||||||
| 35 | ); | ||||||||||
| 36 | 0 | return %list; | |||||||||
| 37 | |||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | # Start things up | ||||||||||
| 41 | # Check for existing log files | ||||||||||
| 42 | # Create new ones, if need be | ||||||||||
| 43 | 0 | ▶ | sub _load { | ||||||||
|
Subroutine
_load: not called CC=6 SCAR=37.4
| |||||||||||
| 44 | |||||||||||
| 45 | 0 | my $self = shift; | |||||||||
| 46 | 0 | my %list = $self->_list(); | |||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | if ( $self->{'Path'} ne 'null' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | foreach ( keys %list ) { | |||||||||
| 50 | 0 | ▶ | if ( -e $_ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | ▶ | open( FILE, $_ ) || croak "Cannot Open $_!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | print FILE "Bot loaded...\n"; | |||||||||
| 53 | 0 | ▶ | close(FILE) || croak "Cannot Close $_!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | } | ||||||||||
| 55 | } | ||||||||||
| 56 | } | ||||||||||
| 57 | else { | ||||||||||
| 58 | 0 | return 0; | |||||||||
| 59 | } | ||||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | # Dump seen info into file | ||||||||||
| 63 | 0 | ▶ | sub bot_log { | ||||||||
|
Subroutine
bot_log: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 64 | |||||||||||
| 65 | 0 | my ( $self, $message ) = @_; | |||||||||
| 66 | 0 | my %list = $self->_list(); | |||||||||
| 67 | |||||||||||
| 68 | 0 | ▶ | if ( $self->{'Path'} ne 'null' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | ▶ | open( FILE, ">>$list{'Bot'}" ) || croak "Cannot Open $list{'Bot'}!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | print FILE "$message\n"; | |||||||||
| 71 | 0 | ▶ | close(FILE) || croak "Cannot Close $list{'Bot'}!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | } | ||||||||||
| 73 | else { | ||||||||||
| 74 | 0 | return 0; | |||||||||
| 75 | } | ||||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | # Records server events. | ||||||||||
| 79 | 0 | ▶ | sub serv_log { | ||||||||
|
Subroutine
serv_log: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 80 | |||||||||||
| 81 | 0 | my ( $self, $message ) = @_; | |||||||||
| 82 | 0 | my %list = $self->_list(); | |||||||||
| 83 | |||||||||||
| 84 | 0 | ▶ | if ( $self->{'Path'} ne 'null' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | 0 | ▶ | open( FILE, ">>$list{'Server'}" ) || croak "Cannot Open $list{'Server'}!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | print FILE "$message\n"; | |||||||||
| 87 | 0 | ▶ | close(FILE) || croak "Cannot Close $list{'Server'}!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | } | ||||||||||
| 89 | else { | ||||||||||
| 90 | 0 | return 0; | |||||||||
| 91 | } | ||||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | # Records channel events | ||||||||||
| 95 | 0 | ▶ | sub chan_log { | ||||||||
|
Subroutine
chan_log: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 96 | |||||||||||
| 97 | 0 | my ( $self, $message ) = @_; | |||||||||
| 98 | 0 | my %list = $self->_list(); | |||||||||
| 99 | |||||||||||
| 100 | 0 | ▶ | if ( $self->{'Path'} ne 'null' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | 0 | ▶ | open( FILE, ">>$list{'Channel'}" ) || croak "Cannot Open $list{'Channel'}!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | 0 | print FILE "$message\n"; | |||||||||
| 103 | 0 | ▶ | close(FILE) || croak "Cannot Close $list{'Channel'}!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | } | ||||||||||
| 105 | else { | ||||||||||
| 106 | 0 | return 0; | |||||||||
| 107 | } | ||||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | # Clear logfile of unwanted seen data | ||||||||||
| 111 | 0 | ▶ | sub clear_log { | ||||||||
|
Subroutine
clear_log: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 112 | |||||||||||
| 113 | 0 | my ( $self, $arg ) = @_; | |||||||||
| 114 | 0 | my %list = $self->_list(); | |||||||||
| 115 | |||||||||||
| 116 | 0 | ▶ | if ( $arg eq 'All' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | 0 | foreach ( keys %list ) { | |||||||||
| 118 | 0 | ▶ | unlink($_) || croak "Cannot Unlink $_!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | } | ||||||||||
| 120 | } | ||||||||||
| 121 | else { | ||||||||||
| 122 | 0 | ▶ | if ( exists $list{$arg} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 0 | ▶ | unlink( $list{$arg} ) || croak "Cannot Unlink $arg!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | 0 | return 1; | |||||||||
| 125 | } | ||||||||||
| 126 | else { | ||||||||||
| 127 | 0 | return 0; | |||||||||
| 128 | } | ||||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | 1 | 1; | |||||||||
| 134 | __END__ | ||||||||||