| 1 | package Bot::Cobalt::Plugin::Extras::Debug; | ||
| 2 | $Bot::Cobalt::Plugin::Extras::Debug::VERSION = '0.021003'; | ||
| 3 | use strictures 2; | ||
| 4 | |||
| 5 | use Bot::Cobalt; | ||
| 6 | use Bot::Cobalt::Common; | ||
| 7 | |||
| 8 | use Data::Dumper; | ||
| 9 | |||
| 10 | sub new { bless [], shift } | ||
| 11 | |||
| 12 | sub Cobalt_register { | ||
| 13 | my ($self, $core) = splice @_, 0, 2; | ||
| 14 | |||
| 15 | my @events = map { 'public_cmd_'.$_ } | ||
| 16 | qw/ | ||
| 17 | dumpcfg | ||
| 18 | dumpstate | ||
| 19 | dumptimers | ||
| 20 | dumpservers | ||
| 21 | dumplangset | ||
| 22 | dumpheap | ||
| 23 | / ; | ||
| 24 | |||
| 25 | register $self, SERVER => [ @events ]; | ||
| 26 | |||
| 27 | $core->log->info("Loaded Debug"); | ||
| 28 | |||
| 29 | PLUGIN_EAT_NONE | ||
| 30 | } | ||
| 31 | |||
| 32 | sub Cobalt_unregister { | ||
| 33 | my ($self, $core) = splice @_, 0, 2; | ||
| 34 | $core->log->info("Unloaded DEBUG"); | ||
| 35 | PLUGIN_EAT_NONE | ||
| 36 | } | ||
| 37 | |||
| 38 | sub Bot_public_cmd_dumpcfg { | ||
| 39 | my ($self, $core) = splice @_, 0, 2; | ||
| 40 | my $msg = ${ $_[0] }; | ||
| 41 | my $context = $msg->context; | ||
| 42 | my $src_nick = $msg->src_nick; | ||
| 43 | |||
| 44 | return PLUGIN_EAT_ALL unless | ||
| 45 | $core->auth->has_flag($context, $src_nick, 'SUPERUSER'); | ||
| 46 | |||
| 47 | broadcast message => $msg->context, $msg->channel, | ||
| 48 | "Dumping configuration hash to log . . ."; | ||
| 49 | $core->log->warn("dumpcfg called (debugger)"); | ||
| 50 | $core->log->warn(Dumper $core->cfg); | ||
| 51 | |||
| 52 | PLUGIN_EAT_NONE | ||
| 53 | } | ||
| 54 | |||
| 55 | sub Bot_public_cmd_dumpstate { | ||
| 56 | my ($self, $core) = splice @_, 0, 2; | ||
| 57 | my $msg = ${ $_[0] }; | ||
| 58 | my $context = $msg->context; | ||
| 59 | my $src_nick = $msg->src_nick; | ||
| 60 | |||
| 61 | return PLUGIN_EAT_ALL unless | ||
| 62 | $core->auth->has_flag($context, $src_nick, 'SUPERUSER'); | ||
| 63 | |||
| 64 | broadcast message => $msg->context, $msg->channel, | ||
| 65 | "Dumping state hash to log . . ."; | ||
| 66 | $core->log->warn("dumpstate called (debugger)"); | ||
| 67 | $core->log->warn(Dumper $core->State); | ||
| 68 | PLUGIN_EAT_NONE | ||
| 69 | } | ||
| 70 | |||
| 71 | sub Bot_public_cmd_dumptimers { | ||
| 72 | my ($self, $core) = splice @_, 0, 2; | ||
| 73 | my $msg = ${ $_[0] }; | ||
| 74 | my $context = $msg->context; | ||
| 75 | my $src_nick = $msg->src_nick; | ||
| 76 | |||
| 77 | return PLUGIN_EAT_ALL unless | ||
| 78 | $core->auth->has_flag($context, $src_nick, 'SUPERUSER'); | ||
| 79 | |||
| 80 | broadcast message => $msg->context, $msg->channel, | ||
| 81 | "Dumping timer pool to log . . ."; | ||
| 82 | $core->log->warn("dumptimers called (debugger)"); | ||
| 83 | $core->log->warn(Dumper $core->TimerPool); | ||
| 84 | PLUGIN_EAT_NONE | ||
| 85 | } | ||
| 86 | |||
| 87 | sub Bot_public_cmd_dumpservers { | ||
| 88 | my ($self, $core) = splice @_, 0, 2; | ||
| 89 | my $msg = ${ $_[0] }; | ||
| 90 | my $context = $msg->context; | ||
| 91 | my $src_nick = $msg->src_nick; | ||
| 92 | |||
| 93 | return PLUGIN_EAT_ALL unless | ||
| 94 | $core->auth->has_flag($context, $src_nick, 'SUPERUSER'); | ||
| 95 | |||
| 96 | broadcast message => $msg->context, $msg->channel, | ||
| 97 | "Dumping Servers hash to log . . ."; | ||
| 98 | $core->log->warn("dumpservers called (debugger)"); | ||
| 99 | $core->log->warn(Dumper $core->Servers); | ||
| 100 | PLUGIN_EAT_NONE | ||
| 101 | } | ||
| 102 | |||
| 103 | sub Bot_public_cmd_dumplangset { | ||
| 104 | my ($self, $core) = splice @_, 0, 2; | ||
| 105 | my $msg = ${ $_[0] }; | ||
| 106 | my $context = $msg->context; | ||
| 107 | my $src_nick = $msg->src_nick; | ||
| 108 | |||
| 109 | return PLUGIN_EAT_ALL unless | ||
| 110 | $core->auth->has_flag($context, $src_nick, 'SUPERUSER'); | ||
| 111 | |||
| 112 | broadcast message => $msg->context, $msg->channel, | ||
| 113 | "Dumping core language set to log . . ."; | ||
| 114 | $core->log->warn("dumplangset called (debugger)"); | ||
| 115 | $core->log->warn(Dumper $core->lang); | ||
| 116 | PLUGIN_EAT_NONE | ||
| 117 | } | ||
| 118 | |||
| 119 | sub Bot_public_cmd_dumpheap { | ||
| 120 | my ($self, $core) = splice @_, 0, 2; | ||
| 121 | my $msg = ${ $_[0] }; | ||
| 122 | my $context = $msg->context; | ||
| 123 | my $src_nick = $msg->src_nick; | ||
| 124 | |||
| 125 | return PLUGIN_EAT_ALL unless | ||
| 126 | $core->auth->has_flag($context, $src_nick, 'SUPERUSER'); | ||
| 127 | |||
| 128 | try { | ||
| 129 | require Devel::MAT::Dumper; 1 | ||
| 130 | } catch { | ||
| 131 | my $err = "Attempted to dump heap but Devel::MAT could not be loaded: $_"; | ||
| 132 | logger->error($err); | ||
| 133 | broadcast message => $msg->context, $msg->channel, $err; | ||
| 134 | undef | ||
| 135 | } or return PLUGIN_EAT_ALL; | ||
| 136 | |||
| 137 | my $fname = $core->var . '/dump.' . time . '.pmat' ; | ||
| 138 | logger->info("Dumping heap to '$fname'"); | ||
| 139 | broadcast message => $msg->context, $msg->channel, | ||
| 140 | "Dumping heap file to 'var' dir . . ."; | ||
| 141 | Devel::MAT::Dumper::dump( $fname ); | ||
| 142 | |||
| 143 | PLUGIN_EAT_ALL | ||
| 144 | } | ||
| 145 | |||
| 146 | 1; | ||
| 147 | __END__ |