source: trunk/third/perl/lib/if.pm @ 18450

Revision 18450, 861 bytes checked in by zacheiss, 21 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18449, which included commits to RCS files with non-trunk default branches.
Line 
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
Note: See TracBrowser for help on using the repository browser.