From: Michael Andreen Date: Wed, 6 Jan 2010 15:50:38 +0000 (+0100) Subject: Some module preloading and cleanup X-Git-Url: https://ruin.nu/git/?p=NDIRC.git;a=commitdiff_plain;h=17aabe51d5b62ae4bcae5ec3b02757ab5aa65b77 Some module preloading and cleanup --- diff --git a/Bot.pm b/Bot.pm index 53cdf94..9a289f0 100644 --- a/Bot.pm +++ b/Bot.pm @@ -115,9 +115,66 @@ sub sig_usr1 { $kernel->yield( 'refresh' ); } +sub clear_constraint { + my $tc = shift; + + while (1) { + if (ref $tc eq 'MooseX::Meta::TypeConstraint::Structured'){ + for my $t (@{$tc->{type_constraints}}){ + clear_constraint($t); + } + + } + if (ref $tc eq 'Moose::Meta::TypeConstraint::Parameterized'){ + clear_constraint($tc->{type_parameter}); + } + last if ref $tc eq 'HASH'; + last if ref $tc eq ''; + if (defined $tc->{_type_constraint}){ + $tc = $tc->{_type_constraint}; + }elsif(defined $tc->{__type_constraint}){ + $tc = $tc->{__type_constraint}; + }else{ + last; + } + } +} + +sub clear_metains { + my $ins = shift; + + for my $a (@{$ins->{attributes}}){ + for my $m (@{$a->{associated_methods}}){ + $m->{body} = undef; + } + clear_constraint($a->{isa}); + } +} + +sub clear_cycles { + my $c = shift; + + for my $m (values %{$c->meta->{methods}}){ + clear_constraint($m->{type_constraint}); + + my $ps = $m->{parsed_signature}; + for my $p (@{$ps->{_positional_params}->{params}}){ + clear_metains($p->{__MOP__}->{_meta_instance}); + } + + $m->{body} = undef; + } + clear_metains($c->meta->{_meta_instance}); +} + + sub sig_usr2 { my $self = shift @_; + for my $c (values %{$self->disp->commands}){ + clear_cycles($c); + } + $self->disp($self->_build_disp); } diff --git a/Commands/Usermgm.pm b/Commands/Usermgm.pm index 02ff82d..eed0d19 100644 --- a/Commands/Usermgm.pm +++ b/Commands/Usermgm.pm @@ -423,7 +423,7 @@ my $points = class extends NDIRC::Command { method execute ($c,$msg) { my ($nick,$points) = $msg =~ /^(\S+)(?: (-?(:?\d+|\d*\.\d+)))?$/ or die 'ARGS'; - return unless $self->check($c,$nick); + return unless $self->check($c,$nick,$points); $points //= 1; @@ -449,7 +449,7 @@ my $points = class extends NDIRC::Command { } $f->finish; } - method check ($c,$nick) { + method check ($c,$nick,$points) { return 1; } }; @@ -460,7 +460,7 @@ command a => { acl => q(irc_a) }, class { extends $points->name; - method check ($c,$nick) { + method check ($c,$nick,$points) { my ($fleets) = $c->model->selectrow_array(q{ SELECT count(*) FROM raids r JOIN raid_targets rt ON r.id = rt.raid diff --git a/Dispatcher.pm b/Dispatcher.pm index 107ed7e..7dce098 100644 --- a/Dispatcher.pm +++ b/Dispatcher.pm @@ -68,6 +68,7 @@ sub load { warn "couldn't run $file" unless $return; } } + $DISP = undef; } sub command ($$$) { diff --git a/ndbot.pl b/ndbot.pl index a14ee36..1f97e57 100755 --- a/ndbot.pl +++ b/ndbot.pl @@ -22,8 +22,19 @@ use strict; use warnings; use feature ':5.10'; + +#use Devel::Leak::Object qw{ GLOBAL_bless }; use POE qw(Component::IRC::Qnet::State); +use Moose; +use MooseX::Declare; +use MooseX::Declare::StackItem; +use Parse::Method::Signatures::Sig; +use MooseX::Types::TypeDecorator; +use MooseX::Meta::TypeConstraint::ForceCoercion; + +use NDIRC::Bot; + eval "require NDIRC::$ARGV[0]"; die $@ if $@;