6 my $method = shift() ?
'import' : 'unimport';
7 die "Too few arguments to `use if' (some code returning an empty list in list context?)"
9 return unless shift; # CONDITION
11 my $p = $_[0]; # PACKAGE
12 (my $file = "$p.pm") =~ s!::!/!g;
13 require $file; # Works even if $_[0] is a keyword (like open)
14 my $m = $p->can($method);
18 sub import
{ shift; unshift @_, 1; goto &work
}
19 sub unimport
{ shift; unshift @_, 0; goto &work
}
26 if - C<use> a Perl module if a condition holds
30 use if CONDITION, MODULE => ARGUMENTS;
36 use if CONDITION, MODULE => ARGUMENTS;
38 has no effect unless C<CONDITION> is true. In this case the effect is
43 Above C<< => >> provides necessary quoting of C<MODULE>. If not used (e.g.,
44 no ARGUMENTS to give), you'd better quote C<MODULE> yourselves.
48 The current implementation does not allow specification of the
49 required version of the module.
53 Ilya Zakharevich L<mailto:perl-module-if@ilyaz.org>.