Skip Menu |

This queue is for tickets about the MooseX-Event CPAN distribution.

Report information
The Basics
Id: 73922
Status: resolved
Priority: 0/
Queue: MooseX-Event

Owner: WINTER [...]
Requestors: rod.taylor [...]

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)

Subject: Additional Documentation Requested
Download (untitled) / with headers
text/plain 387b
I've been using the module across multiple objects with some success but getting there wasn't entirely obvious and is worth documenting. A brief section showing how to wrap on subs to get your own object reference into $self and perhaps showing how to use handles to share the on/emit functions with subclasses would be useful. Attached is an an example code snippet of what I'm doing.
text/x-perl 945b
use v5.12.4; package Foo; use MooseX::Event; has_events qw{one}; sub BUILD { my $self = shift; $self->on(one => \&fooFunc); return; } sub fooFunc { my ($self, @args) = @_; say "Got event 'one' in Foo"; } package Bar; use Moose; use Data::Dumper; has foopack => (is => 'rw', isa => 'Foo', handles => [qw{on emit}]); sub BUILD { my $self = shift; # This does not give $self the expected reference. It is going to be Foo despite # someFunc being located in Bar package. #$self->on(one => \&someFunc); # This does work. Stripping off the $self reference passed in and replacing with the # local object $self->on(one => sub {$self->someFunc(@_)}); return; } sub someFunc { my ($self, $emitObj, @args) = @_; say "Got event 'one' in Bar"; say "Package : ". (ref $self) . " ". Data::Dumper::Dumper(\@args); return; } package main; my $foo = Foo->new(); my $bar = Bar->new(foopack => $foo); $foo->emit(one => 'arg');
Download (untitled) / with headers
text/plain 445b
Hey there, sorry about not getting back to you sooner, I'd totally forgotten about (I have corrected the module docs to point folks at github now). So your examples are strange to me as you seem to be creating a class that emits an event and then having the same class register to receive the event... I don't think you actually want to do that? It sounds like it would help if I wrote a little tutorial around using it...
Closing this here as discussion has moved to Github.

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to