Thanks, I wanted to be sure that I'm not missing an obscure pragma.
My approach is to declare the lexicals within the destination scope and to inspect the names in the importing package with PadWalker.
Of course this doesn't help importing groups of lexicals so they have to be listed individually, but maybe just syntactic sugar is not the worst approach.
use strict;
use warnings;
package bla;
my ($x,$y)=(42,43);
require export_var;
do {
export_var->import my ($x,$y) ;
print $x,$y;
} for 1..3;
print $x,$y;
use strict;
use warnings;
use feature 'say';
package export_var;
use PadWalker qw[var_name];
use Data::Dump;
my %value = (
'$x'=>1,
'$y'=>2,
);
sub import {
my $pkg=shift;
for my $var (@_) {
$var = $value{ var_name(1,\$var) };
}
}
Cheers Rolf
( addicted to the Perl Programming Language)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.