Pushed on GitHub: http://github.com/mbarbon/wx-perl-pubsub
Mattia Barbon wrote:
Eric Wilhelm wrote:
# from Mattia Barbon
# on Sunday 13 June 2010 01:28:
subscribe( $sender, 'SignalName', $object, 'MethodName' );
subscribe( $sender, 'SignalName', \&_function );
Could this be a method?
$sender->subscribe(SignalName => $object, 'MethodName');
$sender->subscribe(SignalName => sub {...});
I like it slightly better as a function (because the connection is
something that belongs to both the sender and the receiver) but I do not
have a strong opinion on that.
Added two export tags.
use Wx::Perl::PubSub ':local';
exports the functions to the current module, and
use Wx::Perl::PubSub ':global';
adds the methods to all Wx::EvtHandler subclasses.
Also, maybe a way to unsubscribe from all of the subscriptions
$sender->unsubscribe('SignalName');
yes, I'd like to use undef as a wildcard; for example
$sender->unsubscribe(undef, $object)
will disconnect all signals connected to $object
Implemented.
and perhaps a way to get at "what is subscribed" without having to
reconstruct the signatures (e.g. still in scope, etc.)
foreach my $sig ($sender->subscriptions('SignalName')) {
$sender->unsubscribe(SignalName => $sig) if some_condition($sig);
}
Where $sig might be a string of "$object_identifier|MethodName" or
something like that.
I'm not sure: I never needed that when using Qt/C++ and PyQt, and the
interface seems a bit clunky, so I'd rather not add it right now.
In general, this doesn't look very similar to signals/slots (which is
probably a good thing.) The Qt signals/slots model is miserably
polluted with notions of alternate type signatures for the slots and
feels like bashing my head against a wall of C++ to work around the
compile-time type signature checking. What you have proposed may be
better named "pub/sub" -- except I don't see a publish API here.
It is planned; the interface should be something like
emit( $sender, $signal, @args ); # or $sender->emit( ... )
Added, not documented yet.
other missing pieces are a way to retrieve the sender and the wx event
that caused the notification (probably a pair of global functions)
Added.
and a way for external classes to register their own events.
Still missing.
Regards,
Mattia