diff options
author | Ilya Zakharevich <ilya@math.berkeley.edu> | 2001-12-31 13:18:09 -0500 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2002-02-14 21:54:43 +0000 |
commit | cd16c24cb16bb0bd0fa486b8e98c39fcf6ebcf5c (patch) | |
tree | c1cf25ec1a758dd34b0038c6e11438b8254d0f5e /lib/if.pm | |
parent | cef228671c8f137a38217c0c077e19066320c53f (diff) | |
download | perl-cd16c24cb16bb0bd0fa486b8e98c39fcf6ebcf5c.tar.gz |
conditional pragmas
Message-ID: <20011231181809.A29528@math.ohio-state.edu>
p4raw-id: //depot/perl@14694
Diffstat (limited to 'lib/if.pm')
-rw-r--r-- | lib/if.pm | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/if.pm b/lib/if.pm new file mode 100644 index 0000000000..32c4fad45e --- /dev/null +++ b/lib/if.pm @@ -0,0 +1,48 @@ +package if; + +our $VERSION = '0.01'; + +sub work { + my $method = shift() ? 'import' : 'unimport'; + return unless shift; # CONDITION + my $p = shift; # PACKAGE + eval "require $p" or die; # Adds .pm etc if needed + $p->$method(@_) if $p->can($method); +} + +sub import { shift; unshift @_, 1; goto &work } +sub unimport { shift; unshift @_, 0; goto &work } + +1; +__END__ + +=head1 NAME + +if - C<use> a Perl module if a condition holds + +=head1 SYNOPSIS + + use if CONDITION, MODULE => ARGUMENTS; + +=head1 DESCRIPTION + +The construct + + use if CONDITION, MODULE => ARGUMENTS; + +has no effect unless C<CONDITION> is true. In this case the effect is +the same as of + + use MODULE ARGUMENTS; + +=head1 BUGS + +The current implementation does not allow specification of the +required version of the module. + +=head1 AUTHOR + +Ilya Zakharevich L<mailto:perl-module-if@ilyaz.org>. + +=cut + |