ternary operator cond ? foo : bar being parsed as ?...?
[p5sagit/p5-mst-13.2.git] / lib / if.pm
index 32c4fad..700149f 100644 (file)
--- a/lib/if.pm
+++ b/lib/if.pm
@@ -1,13 +1,16 @@
 package if;
 
-our $VERSION = '0.01';
+$VERSION = '0.0401';
 
 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);
+
+  my $p = $_[0];               # PACKAGE
+  (my $file = "$p.pm") =~ s!::!/!g;
+  require $file;               # Works even if $_[0] is a keyword (like open)
+  my $m = $p->can($method);
+  goto &$m if $m;
 }
 
 sub import   { shift; unshift @_, 1; goto &work }