This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Handle magical return values from @INC filter
authorFather Chrysostomos <sprout@cpan.org>
Fri, 9 Aug 2013 20:32:30 +0000 (13:32 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 11 Aug 2013 14:50:22 +0000 (07:50 -0700)
An @INC filter (a subroutined returned by a subroutine in @INC) could
be an lvalue sub that returns a magical scalar for the status.  We
need to account for that.

If we don’t call get-magic (FETCH), we’ll get the last value assigned
to or returned from that scalar.

pp_ctl.c
t/op/incfilter.t

index 1998816..9db13b8 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -5443,6 +5443,7 @@ S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen)
 
        if (count > 0) {
            SV *out = POPs;
+           SvGETMAGIC(out);
            if (SvOK(out)) {
                status = SvIV(out);
            }
index b8efb9b..e43001e 100644 (file)
@@ -13,7 +13,7 @@ use strict;
 use Config;
 use Filter::Util::Call;
 
-plan(tests => 152);
+plan(tests => 153);
 
 unshift @INC, sub {
     no warnings 'uninitialized';
@@ -261,6 +261,14 @@ do sub {
     return $done = 1;
 } or die;
 is ${$::{the_scalar}}, 98732, 'tying $_ in inc filter';
+@lines = ('$::the_scalar', '= "12345"');
+tie my $ret, "main", 1;
+do sub :lvalue {
+    return 0 unless @lines;
+    $_ = shift @lines;
+    return $ret;
+} or die;
+is ${$::{the_scalar}}, 12345, 'returning tied val from inc filter';
 
 
 # d8723a6a74b2c12e wasn't perfect, as the char * returned by SvPV*() can be