X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Dispatcher.pm;h=7c4b0a60618c10eaa56180bf1dcd9729102c38b9;hb=0d63bf9da52cdfe2c9d8850b690032ff539b6398;hp=5da34bdaf5d9ab976419ff8151ceda3275462261;hpb=4f1948e0fe10075464732db5cc2168207c00c7aa;p=NDIRC.git diff --git a/Dispatcher.pm b/Dispatcher.pm index 5da34bd..7c4b0a6 100644 --- a/Dispatcher.pm +++ b/Dispatcher.pm @@ -30,17 +30,23 @@ use NDIRC::Command; has commands => ( - is => 'rw', + is => 'ro', isa => 'HashRef[Object]', default => sub{ {} }, ); has channels => ( - is => 'rw', + is => 'ro', isa => 'HashRef[ArrayRef[Str]]', default => sub{ {} }, ); +has targets => ( + is => 'ro', + isa => 'HashRef[Str]', + default => sub{ {} }, +); + sub load { my $self = shift; @@ -54,7 +60,7 @@ sub load { warn "couldn't do $file: $!" if $!; warn "couldn't run $file" unless $return; }else { - print "Loading $class\n"; + say "\nLoading $class"; $self->load_class($class); } @@ -67,8 +73,8 @@ sub load_class { my @subs = eval "$class->meta->get_method_list"; for my $c (@subs){ my $attr = eval "$class->meta->get_method('$c')->attributes"; - if ($attr){ - print "Command: $c"; + if (@$attr){ + print "Command: $c "; my %c = (channels => ['all']); my @aliases; for (@{$attr}){ @@ -110,7 +116,7 @@ sub has_command { my ($self,$command,$channel) = @_; $channel = lc $channel; - return 0 unless exists $self->commands->{$command}; + return 0 unless defined $command && exists $self->commands->{$command}; my $types = Set::Object->new(@{$self->commands->{$command}->type}); my @types = qw/pub/; @@ -122,6 +128,11 @@ sub has_command { return 0; } +sub set_target { + my ($self,$label,$target) = @_; + $self->targets->{$label} = $target; +} + sub run_command { my ($self,$c,$command,$args) = @_; @@ -146,6 +157,7 @@ sub run_command { } } } + return 1; } 1;