home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 March / PCWorld_2003-03_cd.bin / Software / Topware / activeperl / ActivePerl / Perl / lib / if.pm < prev    next >
Encoding:
Perl POD Document  |  2002-10-22  |  921 b   |  52 lines

  1. package if;
  2.  
  3. our $VERSION = '0.02';
  4.  
  5. sub work {
  6.   my $method = shift() ? 'import' : 'unimport';
  7.   return unless shift;        # CONDITION
  8.  
  9.   my $p = $_[0];        # PACKAGE
  10.   eval "require $p" or die;    # Adds .pm etc if needed
  11.  
  12.   my $m = $p->can($method);
  13.   goto &$m if $m;
  14. }
  15.  
  16. sub import   { shift; unshift @_, 1; goto &work }
  17. sub unimport { shift; unshift @_, 0; goto &work }
  18.  
  19. 1;
  20. __END__
  21.  
  22. =head1 NAME
  23.  
  24. if - C<use> a Perl module if a condition holds
  25.  
  26. =head1 SYNOPSIS
  27.  
  28.   use if CONDITION, MODULE => ARGUMENTS;
  29.  
  30. =head1 DESCRIPTION
  31.  
  32. The construct
  33.  
  34.   use if CONDITION, MODULE => ARGUMENTS;
  35.  
  36. has no effect unless C<CONDITION> is true.  In this case the effect is
  37. the same as of
  38.  
  39.   use MODULE ARGUMENTS;
  40.  
  41. =head1 BUGS
  42.  
  43. The current implementation does not allow specification of the
  44. required version of the module.
  45.  
  46. =head1 AUTHOR
  47.  
  48. Ilya Zakharevich L<mailto:perl-module-if@ilyaz.org>.
  49.  
  50. =cut
  51.  
  52.