6 my $method = shift() ? 'import' : 'unimport';
8 "Too few arguments to `use if' (some code returning an empty list in list context?)"
10 return unless shift; # CONDITION
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);
19 sub import { shift; unshift @_, 1; goto &work }
20 sub unimport { shift; unshift @_, 0; goto &work }
27 if - C<use> a Perl module if a condition holds
31 use if CONDITION, MODULE => ARGUMENTS;
37 use if CONDITION, MODULE => ARGUMENTS;
39 has no effect unless C<CONDITION> is true. In this case the effect is
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.
49 The current implementation does not allow specification of the
50 required version of the module.
54 Ilya Zakharevich L<mailto:perl-module-if@ilyaz.org>.