diff --git a/lib/API/IRC.pm b/lib/API/IRC.pm index b69102f..6d7a4a2 100644 --- a/lib/API/IRC.pm +++ b/lib/API/IRC.pm @@ -60,10 +60,10 @@ sub cpart { my ($svr, $chan, $reason) = @_; if (defined $reason) { - Auto::socksnd($svr, "PART $chan :$reason"); + Auto::socksnd($svr, "PART $chan :$reason"); } else { - Auto::socksnd($svr, "PART $chan :Leaving"); + Auto::socksnd($svr, "PART $chan :Leaving"); } return 1; @@ -173,10 +173,10 @@ sub quit { my ($svr, $reason) = @_; if (defined $reason) { - Auto::socksnd($svr, "QUIT :$reason"); + Auto::socksnd($svr, "QUIT :$reason"); } else { - Auto::socksnd($svr, 'QUIT :Leaving'); + Auto::socksnd($svr, 'QUIT :Leaving'); } # Trigger on_disconnect. @@ -202,9 +202,9 @@ sub usrc { my @sii = split m/[@]/xsm, $si[1]; return ( - nick => $si[0], - user => $sii[0], - host => $sii[1] + nick => $si[0], + user => $sii[0], + host => $sii[1] ); } @@ -220,7 +220,7 @@ sub match_mask { # Let's grep the user's mask. if ($mu =~ m/$mh/xsm) { - return 1; + return 1; } return; diff --git a/lib/API/Log.pm b/lib/API/Log.pm index 51b27c5..9ceefa8 100644 --- a/lib/API/Log.pm +++ b/lib/API/Log.pm @@ -21,7 +21,7 @@ sub println my ($out) = @_; if (!defined $out) { - print $RS; + print $RS; } else { print $out.$RS; @@ -36,8 +36,8 @@ sub dbug my ($out) = @_; if ($Auto::DEBUG) { - # We're in debug mode; print it out. - say $out; + # We're in debug mode; print it out. + say $out; } return 1; @@ -57,7 +57,7 @@ sub alog # Create var/ if it doesn't exist. if (!-d "$Auto::bin{var}") { - mkdir "$Auto::bin{var}", 0600; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) + mkdir "$Auto::bin{var}", 0600; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) } # Open the logfile, print the log message to it and close it. @@ -76,29 +76,29 @@ sub expire_logs # Check for invalid values. if ($celog =~ m/[^0-9]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - # Must be numbers only. - return; + # Must be numbers only. + return; } elsif (!$celog) { - # No expire. - return; + # No expire. + return; } # Iterate through each logfile. foreach my $file (glob fpfmt("$Auto::bin{var}/*")) { - my (undef, $file) = split 'bin/../var/', $file; ## no critic qw(BuiltinFunctions::ProhibitStringySplit) + my (undef, $file) = split 'bin/../var/', $file; ## no critic qw(BuiltinFunctions::ProhibitStringySplit) - # Convert filename to UNIX time. - my $yyyy = substr $file, 0, 4; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) - my $mm = substr $file, 4, 2; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) - $mm = $mm - 1; - my $dd = substr $file, 6, 2; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) - my $epoch = timelocal(0, 0, 0, $dd, $mm, $yyyy); + # Convert filename to UNIX time. + my $yyyy = substr $file, 0, 4; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) + my $mm = substr $file, 4, 2; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) + $mm = $mm - 1; + my $dd = substr $file, 6, 2; ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) + my $epoch = timelocal(0, 0, 0, $dd, $mm, $yyyy); - # If it's older than days, delete it. - if (time - $epoch > 86_400 * $celog) { ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) - unlink "$Auto::bin{var}/$file"; - } + # If it's older than days, delete it. + if (time - $epoch > 86_400 * $celog) { ## no critic qw(ValuesAndExpressions::ProhibitMagicNumbers) + unlink "$Auto::bin{var}/$file"; + } } return 1; diff --git a/lib/API/Std.pm b/lib/API/Std.pm index dd6deb0..deaf856 100644 --- a/lib/API/Std.pm +++ b/lib/API/Std.pm @@ -11,8 +11,8 @@ use base qw(Exporter); our (%LANGE, %MODULE, %EVENTS, %HOOKS, %CMDS, %RAWHOOKS); our @EXPORT_OK = qw(conf_get trans err awarn timer_add timer_del cmd_add - cmd_del hook_add hook_del rchook_add rchook_del match_user - has_priv mod_exists ratelimit_check fpfmt); + cmd_del hook_add hook_del rchook_add rchook_del match_user + has_priv mod_exists ratelimit_check fpfmt); # Initialize a module. @@ -26,35 +26,35 @@ sub mod_init { # Check if this module is compatible with this version of Auto. if ($autover !~ m/^3\.0\.0a(7|8)$/xsm) { - API::Log::dbug('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.'); - API::Log::alog('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.'); + API::Log::dbug('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.'); + API::Log::alog('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.'); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: Failed to load '.$name.': Incompatible with your version of Auto.'); } - return; + return; } # Run the module's _init sub. my $mi = eval($pkg.'::_init();'); ## no critic qw(BuiltinFunctions::ProhibitStringyEval) if ($mi) { - # If successful, add to hash. - $MODULE{$name}{name} = $name; - $MODULE{$name}{version} = $version; - $MODULE{$name}{author} = $author; - $MODULE{$name}{pkg} = $pkg; + # If successful, add to hash. + $MODULE{$name}{name} = $name; + $MODULE{$name}{version} = $version; + $MODULE{$name}{author} = $author; + $MODULE{$name}{pkg} = $pkg; - API::Log::dbug('MODULES: '.$name.' successfully loaded.'); - API::Log::alog('MODULES: '.$name.' successfully loaded.'); + API::Log::dbug('MODULES: '.$name.' successfully loaded.'); + API::Log::alog('MODULES: '.$name.' successfully loaded.'); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: '.$name.' successfully loaded.'); } - return 1; + return 1; } else { - # Otherwise, return a failed to load message. - API::Log::dbug('MODULES: Failed to load '.$name.q{.}); - API::Log::alog('MODULES: Failed to load '.$name.q{.}); + # Otherwise, return a failed to load message. + API::Log::dbug('MODULES: Failed to load '.$name.q{.}); + API::Log::alog('MODULES: Failed to load '.$name.q{.}); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: Failed to load '.$name.q{.}); } - return; + return; } } @@ -78,30 +78,30 @@ sub mod_void { # Check if this module exists. if (!defined $MODULE{$module}) { - API::Log::dbug('MODULES: Failed to unload '.$module.'. No such module?'); - API::Log::alog('MODULES: Failed to unload '.$module.'. No such module?'); + API::Log::dbug('MODULES: Failed to unload '.$module.'. No such module?'); + API::Log::alog('MODULES: Failed to unload '.$module.'. No such module?'); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: Failed to unload '.$module.'. No such module?'); } - return; + return; } # Run the module's _void sub. my $mi = eval($MODULE{$module}{pkg}.'::_void();'); ## no critic qw(BuiltinFunctions::ProhibitStringyEval) if ($mi) { - # If successful, delete class from program and delete module from hash. - Class::Unload->unload($MODULE{$module}{pkg}); - delete $MODULE{$module}; - API::Log::dbug('MODULES: Successfully unloaded '.$module.q{.}); - API::Log::alog('MODULES: Successfully unloaded '.$module.q{.}); + # If successful, delete class from program and delete module from hash. + Class::Unload->unload($MODULE{$module}{pkg}); + delete $MODULE{$module}; + API::Log::dbug('MODULES: Successfully unloaded '.$module.q{.}); + API::Log::alog('MODULES: Successfully unloaded '.$module.q{.}); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: Successfully unloaded '.$module.q{.}); } - return 1; + return 1; } else { - # Otherwise, return a failed to unload message. - API::Log::dbug('MODULES: Failed to unload '.$module.q{.}); - API::Log::alog('MODULES: Failed to unload '.$module.q{.}); + # Otherwise, return a failed to unload message. + API::Log::dbug('MODULES: Failed to unload '.$module.q{.}); + API::Log::alog('MODULES: Failed to unload '.$module.q{.}); if (keys %Auto::SOCKET) { API::Log::slog('MODULES: Failed to unload '.$module.q{.}); } - return; + return; } } @@ -128,10 +128,10 @@ sub cmd_del { $cmd = uc $cmd; if (defined $API::Std::CMDS{$cmd}) { - delete $API::Std::CMDS{$cmd}; + delete $API::Std::CMDS{$cmd}; } else { - return; + return; } return 1; @@ -142,12 +142,12 @@ sub event_add { my ($name) = @_; if (!defined $EVENTS{lc $name}) { - $EVENTS{lc $name} = 1; - return 1; + $EVENTS{lc $name} = 1; + return 1; } else { - API::Log::dbug('DEBUG: Attempt to add a pre-existing event ('.lc $name.')! Ignoring...'); - return; + API::Log::dbug('DEBUG: Attempt to add a pre-existing event ('.lc $name.')! Ignoring...'); + return; } } @@ -156,13 +156,13 @@ sub event_del { my ($name) = @_; if (defined $EVENTS{lc $name}) { - delete $EVENTS{lc $name}; - delete $HOOKS{lc $name}; - return 1; + delete $EVENTS{lc $name}; + delete $HOOKS{lc $name}; + return 1; } else { - API::Log::dbug('DEBUG: Attempt to delete a non-existing event ('.lc $name.')! Ignoring...'); - return; + API::Log::dbug('DEBUG: Attempt to delete a non-existing event ('.lc $name.')! Ignoring...'); + return; } } @@ -171,10 +171,10 @@ sub event_run { my ($event, @args) = @_; if (defined $EVENTS{lc $event} and defined $HOOKS{lc $event}) { - foreach my $hk (keys %{ $HOOKS{lc $event} }) { - my $ri = &{ $HOOKS{lc $event}{$hk} }(@args); + foreach my $hk (keys %{ $HOOKS{lc $event} }) { + my $ri = &{ $HOOKS{lc $event}{$hk} }(@args); if ($ri == -1) { last; } - } + } } return 1; @@ -185,16 +185,16 @@ sub hook_add { my ($event, $name, $sub) = @_; if (!defined $API::Std::HOOKS{lc $name}) { - if (defined $API::Std::EVENTS{lc $event}) { - $API::Std::HOOKS{lc $event}{lc $name} = $sub; - return 1; - } - else { - return; - } + if (defined $API::Std::EVENTS{lc $event}) { + $API::Std::HOOKS{lc $event}{lc $name} = $sub; + return 1; + } + else { + return; + } } else { - return; + return; } } @@ -203,11 +203,11 @@ sub hook_del { my ($event, $name) = @_; if (defined $API::Std::HOOKS{lc $event}{lc $name}) { - delete $API::Std::HOOKS{lc $event}{lc $name}; - return 1; + delete $API::Std::HOOKS{lc $event}{lc $name}; + return 1; } else { - return; + return; } } @@ -218,18 +218,18 @@ sub timer_add { # Check for invalid type/time. if ($type =~ m/[^1-2]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - return; + return; } if ($time =~ m/[^0-9]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - return; + return; } if (!defined $Auto::TIMERS{$name}) { - $Auto::TIMERS{$name}{type} = $type; - $Auto::TIMERS{$name}{time} = time + $time; - if ($type == 2) { $Auto::TIMERS{$name}{secs} = $time; } - $Auto::TIMERS{$name}{sub} = $sub; - return 1; + $Auto::TIMERS{$name}{type} = $type; + $Auto::TIMERS{$name}{time} = time + $time; + if ($type == 2) { $Auto::TIMERS{$name}{secs} = $time; } + $Auto::TIMERS{$name}{sub} = $sub; + return 1; } return 1; @@ -241,8 +241,8 @@ sub timer_del { $name = lc $name; if (defined $Auto::TIMERS{$name}) { - delete $Auto::TIMERS{$name}; - return 1; + delete $Auto::TIMERS{$name}; + return 1; } return; @@ -285,10 +285,10 @@ sub conf_get { # Create an array out of the value. my @val; if ($value =~ m/:/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - @val = split m/[:]/sm, $value; ## no critic qw(RegularExpressions::RequireExtendedFormatting) + @val = split m/[:]/sm, $value; ## no critic qw(RegularExpressions::RequireExtendedFormatting) } else { - @val = ($value); + @val = ($value); } # Undefine this as it's unnecessary now. undef $value; @@ -298,31 +298,31 @@ sub conf_get { # Return the requested configuration value(s). if ($count == 1) { - if (ref $Auto::SETTINGS{$val[0]} eq 'HASH') { - return %{ $Auto::SETTINGS{$val[0]} }; - } - else { - return $Auto::SETTINGS{$val[0]}; - } + if (ref $Auto::SETTINGS{$val[0]} eq 'HASH') { + return %{ $Auto::SETTINGS{$val[0]} }; + } + else { + return $Auto::SETTINGS{$val[0]}; + } } elsif ($count == 2) { - if (ref $Auto::SETTINGS{$val[0]}{$val[1]} eq 'HASH') { - return %{ $Auto::SETTINGS{$val[0]}{$val[1]} }; - } - else { - return $Auto::SETTINGS{$val[0]}{$val[1]}; - } + if (ref $Auto::SETTINGS{$val[0]}{$val[1]} eq 'HASH') { + return %{ $Auto::SETTINGS{$val[0]}{$val[1]} }; + } + else { + return $Auto::SETTINGS{$val[0]}{$val[1]}; + } } elsif ($count == 3) { - if (ref $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} eq 'HASH') { - return %{ $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} }; - } - else { - return $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]}; - } + if (ref $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} eq 'HASH') { + return %{ $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]} }; + } + else { + return $Auto::SETTINGS{$val[0]}{$val[1]}{$val[2]}; + } } else { - return; + return; } } @@ -332,11 +332,11 @@ sub trans { $id =~ s/ /_/gsm; if (defined $API::Std::LANGE{$id}) { - return sprintf $API::Std::LANGE{$id}, @_; + return sprintf $API::Std::LANGE{$id}, @_; } else { - $id =~ s/_/ /gsm; - return $id; + $id =~ s/_/ /gsm; + return $id; } } @@ -349,12 +349,12 @@ sub match_user { my %uhp = conf_get('user'); foreach my $userkey (keys %uhp) { - # For each user block. - my %ulhp = %{ $uhp{$userkey} }; - foreach my $uhk (keys %ulhp) { + # For each user block. + my %ulhp = %{ $uhp{$userkey} }; + foreach my $uhk (keys %ulhp) { # For each user. - if ($uhk eq 'net') { + if ($uhk eq 'net') { if (defined $user{svr}) { if (lc $user{svr} ne lc(($ulhp{$uhk})[0][0])) { # config.user:net conflicts with irc.user:svr. @@ -363,13 +363,13 @@ sub match_user { } } elsif ($uhk eq 'mask') { - # Put together the user information. - my $mask = $user{nick}.q{!}.$user{user}.q{@}.$user{host}; - if (API::IRC::match_mask($mask, ($ulhp{$uhk})[0][0])) { - # We've got a host match. - return $userkey; - } - } + # Put together the user information. + my $mask = $user{nick}.q{!}.$user{user}.q{@}.$user{host}; + if (API::IRC::match_mask($mask, ($ulhp{$uhk})[0][0])) { + # We've got a host match. + return $userkey; + } + } elsif ($uhk eq 'chanstatus' and defined $ulhp{'net'}) { my ($ccst, $ccnm) = split m/[:]/sm, ($ulhp{$uhk})[0][0]; ## no critic qw(RegularExpressions::RequireExtendedFormatting) my $svr = $ulhp{net}[0]; @@ -390,7 +390,7 @@ sub match_user { } } } - } + } } return; @@ -401,13 +401,13 @@ sub has_priv { my ($cuser, $cpriv) = @_; if (conf_get("user:$cuser:privs")) { - my $cups = (conf_get("user:$cuser:privs"))[0][0]; + my $cups = (conf_get("user:$cuser:privs"))[0][0]; - if (defined $Auto::PRIVILEGES{$cups}) { - foreach (@{ $Auto::PRIVILEGES{$cups} }) { - if ($_ eq $cpriv or $_ eq 'ALL') { return 1; } - } - } + if (defined $Auto::PRIVILEGES{$cups}) { + foreach (@{ $Auto::PRIVILEGES{$cups} }) { + if ($_ eq $cpriv or $_ eq 'ALL') { return 1; } + } + } } return; @@ -451,19 +451,19 @@ sub err { ## no critic qw(Subroutines::ProhibitBuiltinHomonyms) # Check for an invalid level. if ($lvl =~ m/[^0-9]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - return; + return; } if ($fatal =~ m/[^0-1]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - return; + return; } # Level 1: Print to screen. if ($lvl >= 1) { - say "ERROR: $msg"; + say "ERROR: $msg"; } # Level 2: Log to file. if ($lvl >= 2) { - API::Log::alog("ERROR: $msg"); + API::Log::alog("ERROR: $msg"); } # Level 3: Log to IRC. if ($lvl >= 3) { @@ -485,7 +485,7 @@ sub awarn { # Check for an invalid level. if ($lvl =~ m/[^0-9]/sm) { ## no critic qw(RegularExpressions::RequireExtendedFormatting) - return; + return; } # Level 1: Print to screen. @@ -494,7 +494,7 @@ sub awarn { } # Level 2: Log to file. if ($lvl >= 2) { - API::Log::alog("WARNING: $msg"); + API::Log::alog("WARNING: $msg"); } # Level 3: Log to IRC. if ($lvl >= 3) {