in reply to (tye)Re: Debugger, use strict, use warnings
in thread Debugger, use strict, use warnings

Making pragma logic move up an extra level of scope is easiest done by using caller to get your caller's package name and then doing an eval which sets the package and then calls the pragma.

There are various compilation/runtime timing issues you have to get straight of course. But that will work.

  • Comment on Re (tilly) 2: Debugger, use strict, use warnings

Replies are listed 'Best First'.
(tye)Re2: Debugger, use strict, use warnings
by tye (Sage) on Apr 10, 2001 at 21:26 UTC

    I'd like to see an example. I believe that pragmas affect the scope that is one level up not on the package that is one level up so I don't see how your suggestion would do any good.

            - tye (but my friends call me "Tye")
      My bad. I was thinking of vars. For pragmas you have to be a little creative. But if you use what I learned at Re (tilly) 1: How does strict work?, it is doable but slightly tricky.

      Perhaps an example would be best.

      Suppose that you wanted a version of strict and vars wrapped up in one, takes one argument list and splits it in the obvious way between strict and vars...

      package my_strict; use strict; use vars; sub import { shift; # I know my class name I hope my (@vars, @strictures); foreach (@_) { if (/\W/) { push @vars, $_; } else { push @strictures, $_; } } my $pkg = caller; $^H = eval " package $pkg; no strict; use strict qw(@strictures); vars->import(\@vars); \$^H; "; } 1;
      Is that what you wanted?

        After playing with this for a while, it boils down to the fact that you can't get the pragma to bubble up an extra level but you can cut'n'paste (varying amounts of) code from the pragma's *.pm file into your own *.pm in order to create your own custom pragma which does the same thing (which seems obvious now but sure didn't a few minutes ago).

        Anyway, the e.pm I wanted above can be had rather simply as:

        package e; require strict; require warnings; sub import { &strict::import; &warnings::import; } 1;

                - tye (but my friends call me "Tye")