]> ruin.nu Git - NDIRC.git/blobdiff - Dispatcher.pm
Need to send a real value to execute when the role isn't available
[NDIRC.git] / Dispatcher.pm
index ccfeb1371329689a2608b810101bc7dd7c2cbc11..7c4b0a60618c10eaa56180bf1dcd9729102c38b9 100644 (file)
@@ -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}){
@@ -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;