This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [ID 20020422.003] Suggestion in Perl 5.6.1 installation on AIX
[perl5.git] / lib / if.pm
CommitLineData
cd16c24c
IZ
1package if;
2
3our $VERSION = '0.01';
4
5sub work {
6 my $method = shift() ? 'import' : 'unimport';
7 return unless shift; # CONDITION
8 my $p = shift; # PACKAGE
9 eval "require $p" or die; # Adds .pm etc if needed
10 $p->$method(@_) if $p->can($method);
11}
12
13sub import { shift; unshift @_, 1; goto &work }
14sub unimport { shift; unshift @_, 0; goto &work }
15
161;
17__END__
18
19=head1 NAME
20
21if - C<use> a Perl module if a condition holds
22
23=head1 SYNOPSIS
24
25 use if CONDITION, MODULE => ARGUMENTS;
26
27=head1 DESCRIPTION
28
29The construct
30
31 use if CONDITION, MODULE => ARGUMENTS;
32
33has no effect unless C<CONDITION> is true. In this case the effect is
34the same as of
35
36 use MODULE ARGUMENTS;
37
38=head1 BUGS
39
40The current implementation does not allow specification of the
41required version of the module.
42
43=head1 AUTHOR
44
45Ilya Zakharevich L<mailto:perl-module-if@ilyaz.org>.
46
47=cut
48