| 1 | # | ||
| 2 | # This file is part of Tk-Role-HasWidgets | ||
| 3 | # | ||
| 4 | # This software is copyright (c) 2010 by Jerome Quelin. | ||
| 5 | # | ||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||
| 8 | # | ||
| 9 | 1 | ▶ | use 5.010; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | package Tk::Role::HasWidgets; | ||
| 14 | { | ||
| 15 | 1 | $Tk::Role::HasWidgets::VERSION = '1.112380'; | |
| 16 | } | ||
| 17 | # ABSTRACT: keep track of your tk widgets | ||
| 18 | |||
| 19 | 1 | ▶ | use Moose::Role 0.92; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 1 | ▶ | use MooseX::Has::Sugar; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | # a hash to store the widgets for easier reference. | ||
| 25 | has _widgets => ( | ||
| 26 | ro, | ||
| 27 | traits => ['Hash'], | ||
| 28 | isa => 'HashRef', | ||
| 29 | 0 | ▶ | default => sub { {} }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 30 | 1 | handles => { | |
| 31 | _set_w => 'set', | ||
| 32 | _w => 'get', | ||
| 33 | _del_w => 'delete', | ||
| 34 | _clear_w => 'clear', | ||
| 35 | }, | ||
| 36 | ); | ||
| 37 | |||
| 38 | 1 | ▶ | no Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 39 | 1 | 1; | |
| 40 | |||
| 41 | |||
| 42 | =pod | ||
| 43 | |||
| 44 | =head1 NAME | ||
| 45 | |||
| 46 | Tk::Role::HasWidgets - keep track of your tk widgets | ||
| 47 | |||
| 48 | =head1 VERSION | ||
| 49 | |||
| 50 | version 1.112380 | ||
| 51 | |||
| 52 | =head1 SYNOPSIS | ||
| 53 | |||
| 54 | package Your::Tk::Window::Class; | ||
| 55 | |||
| 56 | use Moose; | ||
| 57 | with 'Tk::Role::HasWidgets'; | ||
| 58 | |||
| 59 | # store a button | ||
| 60 | $self->_set_w( my_button => $button ); | ||
| 61 | |||
| 62 | # later on, in one of the methods | ||
| 63 | $self->_w( 'my_button' )->configure( ... ); | ||
| 64 | |||
| 65 | # when no longer needed: | ||
| 66 | $self->_del_w( 'my_button' ); | ||
| 67 | |||
| 68 | =head1 DESCRIPTION | ||
| 69 | |||
| 70 | When programming L<Tk>, it's almost always a good idea to keep a | ||
| 71 | reference to the widgets that you created in the interface. Most of the | ||
| 72 | time, a simple hash is enough; but it is usually wrapped up in methods | ||
| 73 | to make the hash private to the window object. And of course, those | ||
| 74 | methods are duplicated in all modules, under a form or another. | ||
| 75 | |||
| 76 | Since duplication is bad, this module implements a L<Moose> role | ||
| 77 | implementing those methods once and forever. This implies that your | ||
| 78 | class is using L<Moose> in order to consume the role. | ||
| 79 | |||
| 80 | =head2 About the method names | ||
| 81 | |||
| 82 | The methods featured in this role begin with C<_>, that is, they are | ||
| 83 | following Perl convention of private methods. This is on purpose: | ||
| 84 | remember that this method is a role, consumed by your class. And you | ||
| 85 | don't want those methods to be available outside of the window | ||
| 86 | class, do you? | ||
| 87 | |||
| 88 | =head1 METHODS | ||
| 89 | |||
| 90 | =head2 _set_w | ||
| 91 | |||
| 92 | $object->_set_w( $name, $widget ); | ||
| 93 | |||
| 94 | Store a reference to C<$widget> and associate it to C<$name>. | ||
| 95 | |||
| 96 | =head2 _w | ||
| 97 | |||
| 98 | my $widget = $object->_w( $name ); | ||
| 99 | |||
| 100 | Get back the C<$widget> reference associated to C<$name>. | ||
| 101 | |||
| 102 | =head2 _del_w | ||
| 103 | |||
| 104 | $object->_del_w( $name ); | ||
| 105 | |||
| 106 | Delete the C<$name> reference to a widget. | ||
| 107 | |||
| 108 | =head2 _clear_w | ||
| 109 | |||
| 110 | Empty the widget references. | ||
| 111 | |||
| 112 | =head1 SEE ALSO | ||
| 113 | |||
| 114 | You can look for information on this module at: | ||
| 115 | |||
| 116 | =over 4 | ||
| 117 | |||
| 118 | =item * Search CPAN | ||
| 119 | |||
| 120 | L<http://search.cpan.org/dist/Tk-Role-HasWidgets> | ||
| 121 | |||
| 122 | =item * See open / report bugs | ||
| 123 | |||
| 124 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tk-Role-HasWidgets> | ||
| 125 | |||
| 126 | =item * Git repository | ||
| 127 | |||
| 128 | L<http://github.com/jquelin/tk-role-haswidgets> | ||
| 129 | |||
| 130 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 131 | |||
| 132 | L<http://annocpan.org/dist/Tk-Role-HasWidgets> | ||
| 133 | |||
| 134 | =item * CPAN Ratings | ||
| 135 | |||
| 136 | L<http://cpanratings.perl.org/d/Tk-Role-HasWidgets> | ||
| 137 | |||
| 138 | =back | ||
| 139 | |||
| 140 | =head1 AUTHOR | ||
| 141 | |||
| 142 | Jerome Quelin | ||
| 143 | |||
| 144 | =head1 COPYRIGHT AND LICENSE | ||
| 145 | |||
| 146 | This software is copyright (c) 2010 by Jerome Quelin. | ||
| 147 | |||
| 148 | This is free software; you can redistribute it and/or modify it under | ||
| 149 | the same terms as the Perl 5 programming language system itself. | ||
| 150 | |||
| 151 | =cut | ||
| 152 | |||
| 153 | |||
| 154 | __END__ | ||