Commit | Line | Data |
cd16c24c |
1 | package if; |
2 | |
2f761939 |
3 | $VERSION = '0.0401'; |
cd16c24c |
4 | |
5 | sub work { |
6 | my $method = shift() ? 'import' : 'unimport'; |
7 | return unless shift; # CONDITION |
a3e5cfd4 |
8 | |
9 | my $p = $_[0]; # PACKAGE |
b9761643 |
10 | (my $file = "$p.pm") =~ s!::!/!g; |
2f761939 |
11 | require $file; # Works even if $_[0] is a keyword (like open) |
a3e5cfd4 |
12 | my $m = $p->can($method); |
13 | goto &$m if $m; |
cd16c24c |
14 | } |
15 | |
16 | sub import { shift; unshift @_, 1; goto &work } |
17 | sub unimport { shift; unshift @_, 0; goto &work } |
18 | |
19 | 1; |
20 | __END__ |
21 | |
22 | =head1 NAME |
23 | |
24 | if - C<use> a Perl module if a condition holds |
25 | |
26 | =head1 SYNOPSIS |
27 | |
28 | use if CONDITION, MODULE => ARGUMENTS; |
29 | |
30 | =head1 DESCRIPTION |
31 | |
32 | The construct |
33 | |
34 | use if CONDITION, MODULE => ARGUMENTS; |
35 | |
36 | has no effect unless C<CONDITION> is true. In this case the effect is |
37 | the same as of |
38 | |
39 | use MODULE ARGUMENTS; |
40 | |
41 | =head1 BUGS |
42 | |
43 | The current implementation does not allow specification of the |
44 | required version of the module. |
45 | |
46 | =head1 AUTHOR |
47 | |
48 | Ilya Zakharevich L<mailto:perl-module-if@ilyaz.org>. |
49 | |
50 | =cut |
51 | |