Mixin::...h::Event(3)

πŸ“¦ version 2.000, in alpine 3.24

πŸ¦‹ Mixin::Event::Dispatch::Event β€” an event object πŸ¦‹

So this whole page lives in the Mixin::Event::Dispatch::Event neighborhood of the Perl docs β€” it's a User Contributed Perl Documentation page, bestie, and it's literally all about one little object: the event itself. πŸ’…


✨ VERSION ✨

version 2.000 β€” that's the vibe check result, we're on 2.000. πŸŽ€


🌸 SYNOPSIS 🌸

Okay so here's the whole thing in action, copying exactly:

 my $self = shift;
 my $ev = Mixin::Event::Dispatch::Event->new(
   name => 'some_event',
   instance => $self,
 );
 $ev->dispatch;

That's it. That's the whole flex. Build the event, then dispatch it. Slay. ⭐


πŸ’– DESCRIPTION πŸ’–

This class hands you an object you can use to actually interact with the current event β€” like, the event that's happening right now, in your handler, in real time. That's the entire job. Iconic, honestly. 🫢


🧚 METHODS 🧚

πŸ“ new

Constructor time! It takes these named parameters, and yes, all of them are named:

  • name β€” the name of this event πŸ’œ
  • instance β€” the originating instance πŸ‘‘
  • parent β€” another Mixin::Event::Dispatch::Event object, but only if we got invoked from inside an existing handler 🌈
  • handlers β€” the list of handlers for this event ✨
Ngl, the implementation here is peculiar on purpose β€” they're assuming that time is of the essence. πŸƒβ€β™€οΈπŸ’¨ Also important: this constructor is rarely called in practice, because Mixin::Event::Dispatch uses bless directly instead. So don't be shocked if you never touch it.

Returns $self. πŸ’…


πŸŽ€ READ-ONLY ACCESSORS πŸŽ€

🌸 name

Returns the name of this event. That's it, that's the method. πŸ¦‹

πŸ”₯ is_deferred

Returns true if this event has been deferred. What that actually means: another handler is active, and it has allowed the remaining handlers to take over the event β€” and once those other handlers finish up, the original handler gets resumed. So it's like a "brb, someone else is driving" flag. 😭

πŸ’€ is_stopped

Returns true if this event has been stopped. Meaning: no further handlers will be called. Full stop, no cap. πŸ›‘

⭐ instance

Returns the original object instance that the invoke_event method in Mixin::Event::Dispatch was called on.

Heads up though β€” this can be different from the instance we're currently handling, in cases like event delegation. So don't assume they're the same, bestie. πŸ™ˆ

🧚 parent

Returns the parent Mixin::Event::Dispatch::Event, if there was one. And usually there wasn't. πŸ’€

πŸ“ handlers

Returns a list of the remaining handlers for this event. Anything that's already been called gets removed from this list, so it's a live "who's left" roster. πŸ‘‘

πŸ’… stop

Stops processing for this event. Prevents any further event handlers from being called. The nuclear option, and sometimes you just need it. πŸ”₯

🌈 dispatch

Dispatches this event. It takes the parameters that were originally passed to invoke_event in Mixin::Event::Dispatch β€” with the exception of the event name β€” and passes them on to the defined handlers. So it's like forwarding the group chat to the handlers. πŸ“²

Returns $self. ✨

πŸŽ€ play

Continues the current event. Do not use. 🚨

The semantics here are subject to change, so seriously, avoid this and consider defer instead. And plot twist: currently it does nothing anyway.

Returns $self. πŸ™ˆ

πŸ¦‹ defer

Defers this event. πŸ’œ

Cause: the remaining handlers get called, and the event gets marked as is_deferred.

Here's the example, exactly as given:

 sub {
  my $ev = shift;
  print "Deferring\n";
  $ev->defer(@_);
  print "Finished deferring\n";
 }

Returns $self. ⭐

🫢 unsubscribe

Unsubscribes the current handler from the event that we're processing at the moment. Perfect for one-shot handlers or limited-lifetime handlers β€” you know, the "I'm only here for a few calls" kind of energy. ✌️

The example, verbatim:

 my $count = 0;
 $obj->subscribeto_event(
   som_event => sub {
     my $ev = shift;
     return $ev->unsubscribe if ++$count > 3;
     print "Current count: $count\n";
   }
 );
 $obj->invoke_event('some_event') for 1..5;

Returns $self. πŸ’–

πŸ’€ debug_print

Shows a debug message. It should only be called if the appropriate (compile-time) flag is set, like this:

 $self->debug_print(...) if DEBUG;

and not by expecting this:

 $self->debug_print(...);

to do the checking for you. It won't. It's not doing that. You have to guard it yourself. 😭

Returns $self. 🌸


πŸ‘‘ AUTHOR πŸ‘‘

Tom Molesworth <cpan@perlsite.co.uk> β€” the main character who wrote all this. 🫢


🌈 LICENSE 🌈

Copyright Tom Molesworth 2012-2014. Licensed under the same terms as Perl itself.


and that's the whole page, bestie β€” go forth and dispatch πŸ’…βœ¨

Sign-off vibes: this page is from perl v5.42.2, dated 2026-02-15 β€” remember it when you're citing your sources in the group chat πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from