lib/Tk/Sugar.pm

filter: Statementstmt 0.0% 0 / 46 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 40 Podpod 100% 40 / 40 totaltotal 31.7% 40 / 126 CC 1 SCAR 6.9
CC
1
Cov
0%
top
2.0
bottom
2.0
left
2.0
CRAP 2.0
↑ Summary
1 #
2 # This file is part of Tk-Sugar
3 #
4 # This software is copyright (c) 2009 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 use 5.008;
10 use strict;
11 use warnings;
12  
13 package Tk::Sugar;
14 our $VERSION = '1.093190';
15  
16  
17 # ABSTRACT: Sugar syntax for Tk
18  
19 use Sub::Exporter -setup => {
20 exports => [ qw{
21 top bottom left right
22 fillx filly fill2 xfillx xfilly xfill2 expand
23 pad pad1 pad2 pad5 pad10 pad20 padx pady
24 ipad ipad1 ipad2 ipad5 ipad10 ipad20 ipadx ipady
25 enabled disabled
26 N S E W C NE NW SE SW
27 horizontal vertical
28 } ],
29 groups => {
30 fill => [ qw{ fillx filly fill2 xfillx xfilly xfill2 expand } ],
31 side => [ qw{ top bottom left right } ],
32 pad => [ qw{ pad pad1 pad2 pad5 pad10 pad20 padx pady } ],
33 ipad => [ qw{ ipad ipad1 ipad2 ipad5 ipad10 ipad20 ipadx ipady } ],
34 pack => [ qw{ -fill -side -pad -ipad } ],
35 state => [ qw{ enabled disabled } ],
36 anchor => [ qw{ N S E W C NE NW SE SW } ],
37 orient => [ qw{ horizontal vertical } ],
38 options => [ qw{ -state -anchor -orient } ],
39 default => [ qw{ -pack -options } ],
40 }
41 };
42  
43 ## no critic (ProhibitSubroutinePrototypes)
44  
45 # -- pack options
46 # cf perldoc Tk::pack for more information
47  
48 # pack sides
49 0 ▶sub top () { return ( -side => 'top' ); }
Subroutine top: not called CC=1 SCAR=6.9
Pod documented
50 0 ▶sub bottom () { return ( -side => 'bottom' ); }
Subroutine bottom: not called CC=1 SCAR=6.9
Pod documented
51 0 ▶sub left () { return ( -side => 'left' ); }
Subroutine left: not called CC=1 SCAR=6.9
Pod documented
52 0 ▶sub right () { return ( -side => 'right' ); }
Subroutine right: not called CC=1 SCAR=6.9
Pod documented
53  
54 # pack fill / expand
55 0 ▶sub fillx () { return ( -fill => 'x' ); }
Subroutine fillx: not called CC=1 SCAR=6.9
Pod documented
56 0 ▶sub filly () { return ( -fill => 'y' ); }
Subroutine filly: not called CC=1 SCAR=6.9
Pod documented
57 0 ▶sub fill2 () { return ( -fill => 'both' ); }
Subroutine fill2: not called CC=1 SCAR=6.9
Pod documented
58 0 ▶sub xfillx () { return ( -expand => 1, -fill => 'x' ); }
Subroutine xfillx: not called CC=1 SCAR=6.9
Pod documented
59 0 ▶sub xfilly () { return ( -expand => 1, -fill => 'y' ); }
Subroutine xfilly: not called CC=1 SCAR=6.9
Pod documented
60 0 ▶sub xfill2 () { return ( -expand => 1, -fill => 'both' ); }
Subroutine xfill2: not called CC=1 SCAR=6.9
Pod documented
61 0 ▶sub expand () { return ( -expand => 1 ); }
Subroutine expand: not called CC=1 SCAR=6.9
Pod documented
62  
63 # padding
64 0 ▶sub pad1 () { return ( -padx => 1, -pady => 1 ); }
Subroutine pad1: not called CC=1 SCAR=6.9
Pod documented
65 0 ▶sub pad2 () { return ( -padx => 2, -pady => 2 ); }
Subroutine pad2: not called CC=1 SCAR=6.9
Pod documented
66 0 ▶sub pad5 () { return ( -padx => 5, -pady => 5 ); }
Subroutine pad5: not called CC=1 SCAR=6.9
Pod documented
67 0 ▶sub pad10 () { return ( -padx => 10, -pady => 10 ); }
Subroutine pad10: not called CC=1 SCAR=6.9
Pod documented
68 0 ▶sub pad20 () { return ( -padx => 20, -pady => 20 ); }
Subroutine pad20: not called CC=1 SCAR=6.9
Pod documented
69 0 ▶sub pad { my $n=shift; return ( -padx => $n, -pady => $n ); }
Subroutine pad: not called CC=1 SCAR=6.9
Pod documented
70 0 ▶sub padx { my $n=shift; return ( -padx => $n ); }
Subroutine padx: not called CC=1 SCAR=6.9
Pod documented
71 0 ▶sub pady { my $n=shift; return ( -pady => $n ); }
Subroutine pady: not called CC=1 SCAR=6.9
Pod documented
72  
73 # internal padding
74 0 ▶sub ipad1 () { return ( -ipadx => 1, -ipady => 1 ); }
Subroutine ipad1: not called CC=1 SCAR=6.9
Pod documented
75 0 ▶sub ipad2 () { return ( -ipadx => 2, -ipady => 2 ); }
Subroutine ipad2: not called CC=1 SCAR=6.9
Pod documented
76 0 ▶sub ipad5 () { return ( -ipadx => 5, -ipady => 5 ); }
Subroutine ipad5: not called CC=1 SCAR=6.9
Pod documented
77 0 ▶sub ipad10 () { return ( -ipadx => 10, -ipady => 10 ); }
Subroutine ipad10: not called CC=1 SCAR=6.9
Pod documented
78 0 ▶sub ipad20 () { return ( -ipadx => 20, -ipady => 20 ); }
Subroutine ipad20: not called CC=1 SCAR=6.9
Pod documented
79 0 ▶sub ipad { my $n=shift; return ( -ipadx => $n, -ipady => $n ); }
Subroutine ipad: not called CC=1 SCAR=6.9
Pod documented
80 0 ▶sub ipadx { my $n=shift; return ( -ipadx => $n ); }
Subroutine ipadx: not called CC=1 SCAR=6.9
Pod documented
81 0 ▶sub ipady { my $n=shift; return ( -ipady => $n ); }
Subroutine ipady: not called CC=1 SCAR=6.9
Pod documented
82  
83  
84 # -- common widget options
85 # cf perldoc Tk::options for more information
86  
87 # widget state
88 0 ▶sub enabled () { return ( -state => 'normal' ); }
Subroutine enabled: not called CC=1 SCAR=6.9
Pod documented
89 0 ▶sub disabled () { return ( -state => 'disabled' ); }
Subroutine disabled: not called CC=1 SCAR=6.9
Pod documented
90  
91 # anchor
92 0 ▶sub N () { return ( -anchor => 'n' ); }
Subroutine N: not called CC=1 SCAR=6.9
Pod documented
93 0 ▶sub S () { return ( -anchor => 's' ); }
Subroutine S: not called CC=1 SCAR=6.9
Pod documented
94 0 ▶sub E () { return ( -anchor => 'e' ); }
Subroutine E: not called CC=1 SCAR=6.9
Pod documented
95 0 ▶sub W () { return ( -anchor => 'w' ); }
Subroutine W: not called CC=1 SCAR=6.9
Pod documented
96 0 ▶sub C () { return ( -anchor => 'center' ); }
Subroutine C: not called CC=1 SCAR=6.9
Pod documented
97 0 ▶sub NE () { return ( -anchor => 'ne' ); }
Subroutine NE: not called CC=1 SCAR=6.9
Pod documented
98 0 ▶sub NW () { return ( -anchor => 'nw' ); }
Subroutine NW: not called CC=1 SCAR=6.9
Pod documented
99 0 ▶sub SE () { return ( -anchor => 'se' ); }
Subroutine SE: not called CC=1 SCAR=6.9
Pod documented
100 0 ▶sub SW () { return ( -anchor => 'sw' ); }
Subroutine SW: not called CC=1 SCAR=6.9
Pod documented
101  
102 # orientation
103 0 ▶sub horizontal () { return ( -orient => 'horizontal' ); }
Subroutine horizontal: not called CC=1 SCAR=6.9
Pod documented
104 0 ▶sub vertical () { return ( -orient => 'vertical' ); }
Subroutine vertical: not called CC=1 SCAR=6.9
Pod documented
105  
106  
107  
108 1;
109  
110  
111 =pod
112  
113 =head1 NAME
114  
115 Tk::Sugar - Sugar syntax for Tk
116  
117 =head1 VERSION
118  
119 version 1.093190
120  
121 =head1 SYNOPSIS
122  
123 use Tk::Sugar qw{ :pack :state };
124  
125 $widget->pack( top, xfill2, pad10 );
126 # equivalent to those pack options:
127 # -side => 'top'
128 # -expand => 1
129 # -fill => 'both'
130 # -padx => 10
131 # -pady => 10
132  
133 $widget->configure( enabled );
134 # equivalent to: -state => 'enabled'
135  
136 =head1 DESCRIPTION
137  
138 L<Tk> is a great graphical toolkit to write desktop applications.
139 However, one can get bothered with the constant typing of quotes and
140 options. L<Tk::Sugar> provides handy subs for common options used when
141 programming Tk.
142  
143 Benefits are obvious:
144  
145 =over 4
146  
147 =item * Reduced typing.
148  
149 The constant need to type C<< => >> and C<''> is fine for one-off cases,
150 but the instant you start using Tk it starts to get annoying.
151  
152 =item * More compact statements.
153  
154 Reduces much of the redundant typing in most cases, which makes your
155 life easier, and makes it take up less visual space, which makes it
156 faster to read.
157  
158 =item * No string worries.
159  
160 Strings are often problematic, since they aren't checked at compile-
161 time. Sometimes it makes spotting an error a difficult task. Using this
162 alleviates that worry.
163  
164 =back
165  
166 =head1 EXPORTS
167  
168 This module is using L<Sub::Exporter> underneath, so you can use all its
169 shenanigans to change the export names.
170  
171 =head2 Exported subs
172  
173 Look below for the list of available subs.
174  
175 =head3 Pack options
176  
177 Traditional packer sides (available as C<:side> export group):
178  
179 =over 4
180  
181 =item * top - equivalent to C<< ( -side => 'top' ) >>
182  
183 =item * bottom - ditto for C<bottom>
184  
185 =item * left - ditto for C<left>
186  
187 =item * right - ditto for C<right>
188  
189 =back
190  
191 Packer expand and filling (available as C<:fill> export group):
192  
193 =over 4
194  
195 =item * fillx - equivalent to C<< ( -fill => 'x' ) >>
196  
197 =item * filly - equivalent to C<< ( -fill => 'y' ) >>
198  
199 =item * fill2 - equivalent to C<< ( -fill => 'both' ) >>
200  
201 =item * xfillx - same as C<fillx> with C<< ( -expand => 1 ) >>
202  
203 =item * xfilly - ditto for C<filly>
204  
205 =item * xfill2 - ditto for C<fill2>
206  
207 =item * expand - equivalent to C<< ( -expand => 1 ) >> if you don't like
208 the C<xfill*> notation
209  
210 =back
211  
212 Packer padding (available as C<:pad> export group):
213  
214 =over 4
215  
216 =item * pad1 - equivalent to C<< ( -padx => 1, -pady => 1 ) >>
217  
218 =item * pad2 - ditto with 2 pixels
219  
220 =item * pad5 - ditto with 5 pixels
221  
222 =item * pad10 - ditto with 10 pixels
223  
224 =item * pad20 - ditto with 20 pixels
225  
226 =item * pad($n) - ditto with $n pixels (function call with one argument)
227  
228 =item * padx($n) - x padding with $n pixels (function call with one argument)
229  
230 =item * pady($n) - y padding with $n pixels (function call with one argument)
231  
232 =back
233  
234 Packer padding (available as C<:ipad> export group):
235  
236 =over 4
237  
238 =item * ipad1 - equivalent to C<< ( -ipadx => 1, -ipady => 1 ) >>
239  
240 =item * ipad2 - ditto with 2 pixels
241  
242 =item * ipad5 - ditto with 5 pixels
243  
244 =item * ipad10 - ditto with 10 pixels
245  
246 =item * ipad20 - ditto with 20 pixels
247  
248 =item * ipad($n) - ditto with $n pixels (function call with one argument)
249  
250 =item * ipadx($n) - internal x padding with $n pixels (function call
251 with one argument)
252  
253 =item * ipady($n) - internal y padding with $n pixels (function call
254 with one argument)
255  
256 =back
257  
258 =head3 Common options
259  
260 Widget state (available as C<:state> export group):
261  
262 =over 4
263  
264 =item * enabled - equivalent to C<< ( -state => 'normal' ) >>
265  
266 =item * disabled - ditto for C<disabled>
267  
268 =back
269  
270 Widget anchor (available as C<:anchor> export group). Note that those
271 subs are upper case, otherwise the sub C<s> would clash with the regex
272 substitution:
273  
274 =over 4
275  
276 =item * N - equivalent to C<< ( -anchor => 'n' ) >>
277  
278 =item * S - ditto with C<s>
279  
280 =item * E - ditto with C<e>
281  
282 =item * W - ditto with C<w>
283  
284 =item * C - ditto with C<center>
285  
286 =item * NE - ditto with C<ne>
287  
288 =item * NW - ditto with C<nw>
289  
290 =item * SE - ditto with C<se>
291  
292 =item * SW - ditto with C<sw>
293  
294 =back
295  
296 Widget orientation (available as C<:orient> export group).:
297  
298 =over 4
299  
300 =item * horizontal - equivalent to C<< ( -orient => 'horizontal' ) >>
301  
302 =item * vertical - ditto with C<vertical>
303  
304 =back
305  
306 =head2 Export groups
307  
308 Beside the individual groups outlined above, the following export groups
309 exist for your convenience:
310  
311 =over 4
312  
313 =item :default
314  
315 This exports all existing subs.
316  
317 =item :pack
318  
319 This exports subs related to L<Tk::pack> options. Same as C<:side>,
320 C<:fill>, C<:pad> and C<:ipad>.
321  
322 =item :options
323  
324 This exports subs related to widget configure options. Same as
325 C<:state>, C<:anchor> and C<:orient>.
326  
327 =back
328  
329 =head1 SEE ALSO
330  
331 You can look for information on this module at:
332  
333 =over 4
334  
335 =item * Search CPAN
336  
337 L<http://search.cpan.org/dist/Tk-Sugar/>
338  
339 =item * Open / report bugs
340  
341 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tk-Sugar>
342  
343 =item * Git repository
344  
345 L<http://github.com/jquelin/tk-sugar.git>
346  
347 =item * AnnoCPAN: Annotated CPAN documentation
348  
349 L<http://annocpan.org/dist/Tk-Sugar>
350  
351 =item * CPAN Ratings
352  
353 L<http://cpanratings.perl.org/d/Tk-Sugar>
354  
355 =back
356  
357 =head1 AUTHOR
358  
359 Jerome Quelin
360  
361 =head1 COPYRIGHT AND LICENSE
362  
363 This software is copyright (c) 2009 by Jerome Quelin.
364  
365 This is free software; you can redistribute it and/or modify it under
366 the same terms as the Perl 5 programming language system itself.
367  
368 =cut
369  
370  
371 __END__
↑ Summary