Debian lenny version packages
[pkg-perl] / deb-src / libtest-harness-perl / libtest-harness-perl-3.12 / t / lib / if.pm
1 package if;
2
3 $VERSION = '0.05';
4
5 sub work {
6     my $method = shift() ? 'import' : 'unimport';
7     die
8       "Too few arguments to `use if' (some code returning an empty list in list context?)"
9       unless @_ >= 2;
10     return unless shift;    # CONDITION
11
12     my $p = $_[0];          # PACKAGE
13     ( my $file = "$p.pm" ) =~ s!::!/!g;
14     require $file;          # Works even if $_[0] is a keyword (like open)
15     my $m = $p->can($method);
16     goto &$m if $m;
17 }
18
19 sub import   { shift; unshift @_, 1; goto &work }
20 sub unimport { shift; unshift @_, 0; goto &work }
21
22 1;
23 __END__
24
25 =head1 NAME
26
27 if - C<use> a Perl module if a condition holds
28
29 =head1 SYNOPSIS
30
31   use if CONDITION, MODULE => ARGUMENTS;
32
33 =head1 DESCRIPTION
34
35 The construct
36
37   use if CONDITION, MODULE => ARGUMENTS;
38
39 has no effect unless C<CONDITION> is true.  In this case the effect is
40 the same as of
41
42   use MODULE ARGUMENTS;
43
44 Above C<< => >> provides necessary quoting of C<MODULE>.  If not used (e.g.,
45 no ARGUMENTS to give), you'd better quote C<MODULE> yourselves.
46
47 =head1 BUGS
48
49 The current implementation does not allow specification of the
50 required version of the module.
51
52 =head1 AUTHOR
53
54 Ilya Zakharevich L<mailto:perl-module-if@ilyaz.org>.
55
56 =cut
57