> or lexically scoped pragmas via %^H/perlpragma.
I've put some hope into this, because pragmas like strict are automatically disabled at the end of the scope.
In reality thats because $^H is localized per scope and has bits flagging the compile time behaviour.
%^H in contrast is only hint where an imported func() can look-up at run-time if it is still in the same scope where it was imported. :/ (see example in perlpragma )
There doesn't seem to be any possibility to automatically trigger unimport
I.e. in the following example the imported func() will still exist outside the functions scope as long I don't trigger an explicit unimport.
sub test { BEGIN {warn "---- function-scope\n"}; use Module; func("function-scope"); # no Module; # uncommenting will cause a compile-time error } test(); func('filescope');
---- function-scope * importing from Module running func(function-scope) at d:/exp/t_lexical_unimport.pl line 13. running func(filescope) at d:/exp/t_lexical_unimport.pl line 19.
my $caller_pack = caller; # --- modulino # run test script if Module not required unless (caller) { use English; my $run =`$EXECUTABLE_NAME t_lexical_unimport.pl`; exit; } use strict; use warnings; package Module; use Carp; sub import { warn "* importing from ",__PACKAGE__,"\n"; no strict 'refs'; *{"${caller_pack}::func"} = \&func; } sub unimport { warn "* unimporting from ",__PACKAGE__,"\n"; no strict 'refs'; delete ${"${caller_pack}::"}{func}; # dirty: deletes whole glob } # ---------- to be exported sub func { carp "running func(@_)"; } 1;
So the only thing I can do is to hack func() in a way to check %^H at run-time if it is still called in the originating scope.
This might be possible for subs but is a hassle for exported variables. (I could only try to use a tie to intercept any access and check $^H )
Am I missing something???
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
In reply to Re^2: [DSL] disabling packages in Perl? (automatic "no Module"?)
by LanX
in thread [DSL] disabling packages in Perl?
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |