summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/if.pm5
-rw-r--r--lib/if.t26
2 files changed, 20 insertions, 11 deletions
diff --git a/lib/if.pm b/lib/if.pm
index 9e140c37d6..700149f625 100644
--- a/lib/if.pm
+++ b/lib/if.pm
@@ -1,6 +1,6 @@
package if;
-$VERSION = '0.04';
+$VERSION = '0.0401';
sub work {
my $method = shift() ? 'import' : 'unimport';
@@ -8,8 +8,7 @@ sub work {
my $p = $_[0]; # PACKAGE
(my $file = "$p.pm") =~ s!::!/!g;
- require $file;
-
+ require $file; # Works even if $_[0] is a keyword (like open)
my $m = $p->can($method);
goto &$m if $m;
}
diff --git a/lib/if.t b/lib/if.t
index 61cc4b2630..d17ff51806 100644
--- a/lib/if.t
+++ b/lib/if.t
@@ -1,15 +1,26 @@
#!./perl
BEGIN {
- chdir 't' if -d 't';
- @INC = '../lib';
+ chdir 't' and @INC = '../lib' if -f 't/TEST';
}
-use Test::More tests => 6;
+my $t = 1;
+print "1..5\n";
+sub ok {
+ print "not " unless shift;
+ print "ok $t # ", shift, "\n";
+ $t++;
+}
my $v_plus = $] + 1;
my $v_minus = $] - 1;
+unless (eval 'use open ":std"; 1') {
+ # pretend that open.pm is present
+ $INC{'open.pm'} = 'open.pm';
+ eval 'sub open::foo{}'; # Just in case...
+}
+
ok( eval "use if ($v_minus > \$]), strict => 'subs'; \${'f'} = 12" eq 12,
'"use if" with a false condition, fake pragma');
@@ -24,8 +35,7 @@ ok( (not defined eval "use if ($v_plus > \$]), strict => 'refs'; \${'f'} = 12"
and $@ =~ /while "strict refs" in use/),
'"use if" with a true condition and a pragma');
-ok( eval "use if 1, Cwd; cwd() || 1;",
- '"use if" with a true condition, module, no arguments, exports');
-
-ok( eval "use if qw/ 1 if 1 strict subs /; \${'f'} = 12" eq 12,
- '"use if" with a module named after keyword');
+# Old version had problems with the module name `open', which is a keyword too
+# Use 'open' =>, since pre-5.6.0 could interpret differently
+ok( (eval "use if ($v_plus > \$]), 'open' => IN => ':crlf'; 12" || 0) eq 12,
+ '"use if" with open');