Skip Menu |

This queue is for tickets about the Scope-Upper CPAN distribution.

Report information
The Basics
Id: 125931
Status: resolved
Priority: 0/
Queue: Scope-Upper

People
Owner: Nobody in particular
Requestors: VLYON [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.01
Fixed in: 0.31



Subject: localized SCALAR doesn't get imported
perl -E 'use strict; use Scope::Upper ":all"; localize "Pkg::Var", \3; localize "Pkg::Var", [1,2]; eval q{package Pkg; say "@Var $Var"}' Variable "$Var" is not imported at (eval 2) line 1. Arrays, Hashes and Subs are all imported correctly, only Scalars are not imported. Patch attached.
Subject: imported-sv.patch
From f9c08b4a865abc49db8c182417c031f1da66c650 Mon Sep 17 00:00:00 2001 From: Vernon Lyon <vlyon@cpan.org> Date: Wed, 25 Jul 2018 19:08:09 +0100 Subject: [PATCH] Set IMPORTED_SV for localised SCALARs --- Upper.xs | 1 + t/20-localize-target.t | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Upper.xs b/Upper.xs index 6f28120..eb2aa75 100644 --- a/Upper.xs +++ b/Upper.xs @@ -957,6 +957,7 @@ static void su_localize(pTHX_ void *ud_) { su_save_gvcv(gv); break; default: + GvIMPORTED_SV_on(gv); gv = (GV *) save_scalar(gv); break; } diff --git a/t/20-localize-target.t b/t/20-localize-target.t index c68a1a3..434495a 100644 --- a/t/20-localize-target.t +++ b/t/20-localize-target.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 70 + 4; +use Test::More tests => 70 + 4 + 4; use Scope::Upper qw<localize UP HERE>; @@ -333,6 +333,23 @@ sub X::foo { 'X::foo' } is(Y->foo, 'X::foo', 'localize "Y::foo", sub { "Y::foo" } => UP [end]'); } +# Imported + +sub is_imported { + my ($pkg, $sig, $val) = @_; + localize $pkg.'::x', $val => HERE; + my $got = eval "package $pkg; \\${sig}x" + or diag $@; + is_deeply $got, $val, "localize imported ${sig}x"; +} + +{ + is_imported 'Scope::Upper::Test::Mock8', '$', \1; + is_imported 'Scope::Upper::Test::Mock6', '@', [ 2, 3 ]; + is_imported 'Scope::Upper::Test::Mock7', '%', { a => 4 }; + is_imported 'Scope::Upper::Test::Mock9', '&', sub { 5 }; +} + # Invalid sub invalid_ref { qr/^Invalid \Q$_[0]\E reference as the localization target/ } -- 2.11.0
Thanks for your report. Although I didn't go for your solution, this was fixed in version 0.31 released a few weeks ago.