Hi again

> 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');
out

---- 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.

Module.pm:
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.