Subject: | Once drops arguments |
Once() seems to lose both the arguments and callers $self that was being
called; on does not.
Please see attached which creates the below output.
Got event 'one' in Bar
Watch via on, in Bar, from Foo, Args: $VAR1 = [
'arg'
];
Got event 'one' in Bar
Watch via once, in Bar, from , Args: $VAR1 = [];
Subject: | failed_once.pl |
use v5.12.4;
package Foo;
use MooseX::Event;
has_events qw{one};
sub BUILD {
my $self = shift;
return;
}
package Bar;
use Moose;
use Data::Dumper;
has foopack => (is => 'rw', isa => 'Foo', handles => [qw{on once emit}]);
sub BUILD {
my $self = shift;
$self->on(one => sub {$self->someFunc('on', @_)});
$self->once(one => sub {$self->someFunc('once', @_)});
return;
}
sub someFunc {
my ($self, $watchType, $emitObj, @args) = @_;
say "Got event 'one' in Bar";
printf("Watch via %s, in %s, from %s, Args: %s\n", $watchType, ref $self, ref $emitObj, Data::Dumper::Dumper(\@args));
return;
}
package main;
my $foo = Foo->new();
my $bar = Bar->new(foopack => $foo);
$foo->emit(one => 'arg');