The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tk::SignalSlot - An alternative to Tk::bind

SYNOPSIS

    use Tk::SignalSlot;

    $w->connect('<1>' => \&callback1);
    $w->connect('<1>' => \&callback2);

    my $id = $w->connect('<<Event>>' => \&callback3);
    ...
    $w->disconnect($id) if $w->is_connected($id);

DESCRIPTION

Tk::SignalSlot provides an alternative to Tk::bind that is more similar to Qt's signal/slot mechanism. The main idea is that multiple callbacks can now be bound to one event. This allows for a more modular and object-oriented approach to Tk::bind which results in simpler, and easier to maintain code.

Please see "RESTRICTIONS" for some important information.

METHODS

Tk::SingalSlot exports three new methods into the Tk:: namespace:

$widget->connect(event, callback)

This method connects the given callback to the event. This means that when the event is triggered, this callback will be executed. Any number of callbacks can be connected to any one event. When the event fires, all connected callbacks will execute in the order they were connected. event is any valid Tk event, and callback is any valid Tk callback.

Upon success, this method returns a unique ID that can be used in the disconnect() method below.

$widget->disconnect(ID);

Given a valid ID (returned by the connect() method), this method disconnects the associated callback from the event. Obviously, this means that when the event fires, this callback will not be executed.

$widget->is_connected(ID);

Returns 1 if the given ID is that of a validly connected callback. Otherwise, returns 0;

RESTRICTIONS

If you decide to use Tk::SignalSlot, then you should stick with it thoroughtout your program. Intermixing Tk::SignalSlot with Tk::bind can have some unpredictable effects since Tk::SignalSlot uses Tk::bind internally.

BUGS

None so far.

AUTHOR

Ala Qumsieh <aqumsieh@cpan.org>

COPYRIGHT

Copyright (c) 2006 Ala Qumsieh. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.