- SEE ALSO
- COPYRIGHT AND LICENSE
Tk::Role::HasWidgets - keep track of your tk widgets
package Your::Tk::Window::Class; use Moose; with 'Tk::Role::HasWidgets'; # store a button $self->_set_w( my_button => $button ); # later on, in one of the methods $self->_w( 'my_button' )->configure( ... ); # when no longer needed: $self->_del_w( 'my_button' );
When programming Tk, it's almost always a good idea to keep a reference to the widgets that you created in the interface. Most of the time, a simple hash is enough; but it is usually wrapped up in methods to make the hash private to the window object. And of course, those methods are duplicated in all modules, under a form or another.
About the method names
The methods featured in this role begin with
_, that is, they are following Perl convention of private methods. This is on purpose: remember that this method is a role, consumed by your class. And you don't want those methods to be available outside of the window class, do you?
$object->_set_w( $name, $widget );
Store a reference to
$widget and associate it to
my $widget = $object->_w( $name );
Get back the
$widget reference associated to
$object->_del_w( $name );
$name reference to a widget.
Empty the widget references.
You can look for information on this module at:
See open / report bugs
AnnoCPAN: Annotated CPAN documentation
COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Jerome Quelin.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.