Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calling events together #38

Open
cooper opened this issue Nov 21, 2016 · 6 comments
Open

calling events together #38

cooper opened this issue Nov 21, 2016 · 6 comments

Comments

@cooper
Copy link
Owner

cooper commented Nov 21, 2016

Evented::Object allows events on different objects to be called simultaneously. I have wanted to bring this idea to Ferret for some time, but it faces new challenges.

One of the main concerns is that callback names must be unique throughout all events being fired. While this rarely causes an issue in Perl due to Evented::Object automatically generating unique callback names, Ferret would face frequent overlap. The "default function" (the one formally defined by a func or method keyword and whose signature determines the signature of the event) is always called default. This means that virtually any two events will each have a callback named default. When firing the events together, only one of them will be executed.

@cooper
Copy link
Owner Author

cooper commented Nov 24, 2016

Evented::Object 5.62 allows multiple callbacks to have the same name. It intelligently guesses which callback you are referring to by considering the object and event name to which the callbacks were attached.

For Ferret this means that things like before, after, cancel, etc. should work as expected when calling events together. If you say before :someName but multiple events have a callback named :someName, it will refer to the one on the same event. But if :someName only exists on an event other than the one to which the callback is attached, it will refer to that one. So basically, it's smart.

Something else neat is that all :default callbacks have the same priority. So if you say before :default, the callback will be executed before all default functions involved in the multi-call.

@cooper
Copy link
Owner Author

cooper commented Nov 24, 2016

so now that Event.callTogether() is functional, the next step is to create some decent-looking way to do something similar to Evented::Object's event listeners. For example, in the IRC::Bot code currently the PRIVMSG handler is manually added to each connection. Instead, there needs to be some way to make the bot "listen to" the connection.

@cooper
Copy link
Owner Author

cooper commented Nov 26, 2016

OK I'm facing another issue. In Perl it is common to fire all events related to an object on that actual object. In Ferret, this would be pretty messy. It Ferret it's more common to store events in a separate object and then call them with _this set to the desired evented object.

This means that in the case of the IRC bot, we would be attaching events to the $bot.handlers and $conn.handlers objects. So the bot handlers would need to "listen to" the connection handlers. Yet, there needs to be a way to access the bot object from the callbacks attached to $bot.handlers.

@cooper
Copy link
Owner Author

cooper commented Nov 26, 2016

I'm thinking the new .*addListener() special method should accept any arguments which will be supplied to the callbacks coming from a certain object. In the case of the bot, this would look something like $conn.handlers.*addListener($bot.handlers, bot: $bot).

@cooper
Copy link
Owner Author

cooper commented Nov 26, 2016

Note that this would result in the listenee holding a reference to the provided arguments until .*removeListener() is called.

@cooper
Copy link
Owner Author

cooper commented Nov 26, 2016

Hmmm, should adding a listener also imply it is a parent? Not sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant