This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update to MakeMaker 6.30
[perl5.git] / lib / if.pm
CommitLineData
cd16c24c
IZ
1package if;
2
2f761939 3$VERSION = '0.0401';
cd16c24c
IZ
4
5sub work {
6 my $method = shift() ? 'import' : 'unimport';
7 return unless shift; # CONDITION
a3e5cfd4
S
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
S
12 my $m = $p->can($method);
13 goto &$m if $m;
cd16c24c
IZ
14}
15
16sub import { shift; unshift @_, 1; goto &work }
17sub unimport { shift; unshift @_, 0; goto &work }
18
191;
20__END__
21
22=head1 NAME
23
24if - 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
32The construct
33
34 use if CONDITION, MODULE => ARGUMENTS;
35
36has no effect unless C<CONDITION> is true. In this case the effect is
37the same as of
38
39 use MODULE ARGUMENTS;
40
41=head1 BUGS
42
43The current implementation does not allow specification of the
44required version of the module.
45
46=head1 AUTHOR
47
48Ilya Zakharevich L<mailto:perl-module-if@ilyaz.org>.
49
50=cut
51