xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/if.pm (revision 0:68f95e015346)
1*0Sstevel@tonic-gatepackage if;
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateour $VERSION = '0.03';
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gatesub work {
6*0Sstevel@tonic-gate  my $method = shift() ? 'import' : 'unimport';
7*0Sstevel@tonic-gate  return unless shift;		# CONDITION
8*0Sstevel@tonic-gate
9*0Sstevel@tonic-gate  my $p = $_[0];		# PACKAGE
10*0Sstevel@tonic-gate  (my $file = "$p.pm") =~ s!::!/!g;
11*0Sstevel@tonic-gate  require $file or die;
12*0Sstevel@tonic-gate
13*0Sstevel@tonic-gate  my $m = $p->can($method);
14*0Sstevel@tonic-gate  goto &$m if $m;
15*0Sstevel@tonic-gate}
16*0Sstevel@tonic-gate
17*0Sstevel@tonic-gatesub import   { shift; unshift @_, 1; goto &work }
18*0Sstevel@tonic-gatesub unimport { shift; unshift @_, 0; goto &work }
19*0Sstevel@tonic-gate
20*0Sstevel@tonic-gate1;
21*0Sstevel@tonic-gate__END__
22*0Sstevel@tonic-gate
23*0Sstevel@tonic-gate=head1 NAME
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gateif - C<use> a Perl module if a condition holds
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate=head1 SYNOPSIS
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate  use if CONDITION, MODULE => ARGUMENTS;
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate=head1 DESCRIPTION
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gateThe construct
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gate  use if CONDITION, MODULE => ARGUMENTS;
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gatehas no effect unless C<CONDITION> is true.  In this case the effect is
38*0Sstevel@tonic-gatethe same as of
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate  use MODULE ARGUMENTS;
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate=head1 BUGS
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gateThe current implementation does not allow specification of the
45*0Sstevel@tonic-gaterequired version of the module.
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gate=head1 AUTHOR
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gateIlya Zakharevich L<mailto:perl-module-if@ilyaz.org>.
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate=cut
52*0Sstevel@tonic-gate
53