| 1 | # You may distribute under the terms of either the GNU General Public License | ||||||||||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||||||||||
| 3 | # | ||||||||||
| 4 | # (C) Paul Evans, 2012-2020 -- leonerd@leonerd.org.uk | ||||||||||
| 5 | |||||||||||
| 6 | package Tickit::Widgets 0.42; | ||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | =head1 NAME | ||||||||||
| 12 | |||||||||||
| 13 | C<Tickit::Widgets> - load several L<Tickit::Widget> classes at once | ||||||||||
| 14 | |||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||
| 16 | |||||||||||
| 17 | use Tickit::Widgets qw( Static VBox HBox ); | ||||||||||
| 18 | |||||||||||
| 19 | Equivalent to | ||||||||||
| 20 | |||||||||||
| 21 | use Tickit::Widget::Static; | ||||||||||
| 22 | use Tickit::Widget::VBox; | ||||||||||
| 23 | use Tickit::Widget::HBox; | ||||||||||
| 24 | |||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||
| 26 | |||||||||||
| 27 | This module provides an C<import> utility to simplify code that uses many | ||||||||||
| 28 | different L<Tickit::Widget> subclasses. Instead of a C<use> line per module, | ||||||||||
| 29 | you can simply C<use> this module and pass it the base name of each class. | ||||||||||
| 30 | It will C<require> each of the modules. | ||||||||||
| 31 | |||||||||||
| 32 | Note that because each Widget module should be a pure object class with no | ||||||||||
| 33 | exports, this utility does not run the C<import> method of the used classes. | ||||||||||
| 34 | |||||||||||
| 35 | An optional version check may be supplied using a C<=> sign: | ||||||||||
| 36 | |||||||||||
| 37 | use Tickit::Widgets qw( HBox=0.48 VBox=0.48 ); | ||||||||||
| 38 | |||||||||||
| 39 | =cut | ||||||||||
| 40 | |||||||||||
| 41 | sub import | ||||||||||
| 42 | 0 | ▶ | { | ||||||||
|
Subroutine
import: not called CC=5 SCAR=34.0
| |||||||||||
| 43 | 0 | shift; # class | |||||||||
| 44 | |||||||||||
| 45 | # Only need to 'require' the modules because they're all clean object | ||||||||||
| 46 | # classes, no need to import any of them | ||||||||||
| 47 | 0 | foreach ( @_ ) { | |||||||||
| 48 | 0 | my $class = $_; # $_ is alias to read-only values; | |||||||||
| 49 | 0 | local $_; # placate bug in Tickit::RenderContext 0.06 | |||||||||
| 50 | |||||||||||
| 51 | 0 | my $version; | |||||||||
| 52 | 0 | ▶ | $class =~ s/=(\d+\.\d+)$// and $version = $1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | $class = "Tickit::Widget::$class" unless $class =~ m/::/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | |||||||||||
| 56 | 0 | ( my $file = "$class.pm" ) =~ s{::}{/}g; | |||||||||
| 57 | |||||||||||
| 58 | 0 | require $file; | |||||||||
| 59 | |||||||||||
| 60 | 0 | ▶ | if( defined $version ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | $class->VERSION( $version ); | |||||||||
| 62 | } | ||||||||||
| 63 | } | ||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | =head1 AUTHOR | ||||||||||
| 67 | |||||||||||
| 68 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||
| 69 | |||||||||||
| 70 | =cut | ||||||||||
| 71 | |||||||||||
| 72 | 1 | 0x55AA; | |||||||||