fix the nasty feature in perl 5.6 with my $ref = $foo if $bar for
[spider.git] / perl / Thingy.pm
index 0ab70dcf95359b0bb792b012eabeee19009492f0..afc2129b913641eaaaf641330781de873bc535cd 100644 (file)
@@ -43,11 +43,12 @@ use DXUtil;
 sub new
 {
        my $class = shift;
+       my $pkg = ref $class || $class;
        my $thing = {@_};
 
        $thing->{origin} ||= $main::mycall;
        
-       bless $thing, $class;
+       bless $thing, $pkg;
        return $thing;
 }
 
@@ -77,7 +78,7 @@ sub send
        # function must return true to make the send happen
        $sub = "before_send_$class";
        if ($thing->can($sub)) {
-               return $thing->$sub($dxchan);
+               return unless $thing->$sub($dxchan);
        }
        
        # generate the protocol line which may (or not) be cached
@@ -112,7 +113,8 @@ sub broadcast
        dbg("Thingy::broadcast: " . $thing->ascii) if isdbg('thing'); 
 
        my @dxchan;
-       my $to ||= $thing->{touser};
+       my $to ||= $thing->{route}; 
+       $to     ||= $thing->{touser};
        $to ||= $thing->{group};
        if ($to && is_callsign($to) && (my $ref = Route::get($to))) {
                dbg("Thingy::broadcast: routing for $to") if isdbg('thing');
@@ -216,7 +218,7 @@ sub ascii
        my $dd = new Data::Dumper([$thing]);
        $dd->Indent(0);
        $dd->Terse(1);
-       $dd->Sortkeys(1);
+       #$dd->Sortkeys(1);
     $dd->Quotekeys($] < 5.005 ? 1 : 0);
        return $dd->Dumpxs;
 }
@@ -241,9 +243,11 @@ sub new_reply
        if ($thing->{group} eq $main::mycall) {
                $out = $thing->new;
                $out->{touser} = $thing->{user} if $thing->{user};
+               $out->{group} = $thing->{origin};
        } elsif (DXChannel::get($thing->{group})) {
                $out = $thing->new(user => $thing->{group});
                $out->{touser} = $thing->{user} if $thing->{user};
+               $out->{group} = $thing->{origin};
        } elsif ($thing->{touser} && DXChannel::get($thing->{touser})) {
                $out = $thing->new(user => $thing->{touser});
                $out->{group} = $thing->{group};