in reply to setting 'no strict refs' in a module from the script

You can always replace &strict::import. Something like this untested piece of code may do:

package StrictDisallow; no warnings; BEGIN { require strict; *o_import = \&strict::import; *strict::import += \&n_import } our %disallow; our @stricts = qw(refs subs vars); sub import { shift; my $namespace = shift; return unless $namespace && @_; %disallow = (%disallow,$namespace,[@_]); } sub n_import { my $caller = caller; if (exists $disallow{$caller}) { my $class = shift; my %temp; if (@_ == 1) { @temp{@stricts} = (); } else { @temp{@_} = (); } delete @temp{@{$disallow{$caller}}}; return unless %temp; @_ = ($class,keys %temp_hash); } &o_import; } 1;

Then you'd use it like:

#!/usr/bin/perl -w use strict; use StrictDisallow Term::Cap => "refs"; ...

Just be certain to use StrictDisallow before loading the modules you wish to restrict.

I hope this helps.

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1

Replies are listed 'Best First'.
Re: Re: setting 'no strict refs' in a module from the script
by zentara (Cardinal) on Jan 26, 2004 at 20:12 UTC
    Wow, that is nice. It would seem that Perl would have this sort of thing built into it. Or maybe there is a reason why it dosn't?

      It's because strict and warnings are meant to help in development and testing. Since you are using these other modules, they should compile properly. The easiest thing is to create a patch, apply it locally and submit it to the module's author.

      On a side note, someone already suggested that I put StrictDisallow.pm on CPAN. I have no interest in it and anyone who wishes to do so is free to do so if they please. If anyone does, though, a shout out would be nice =P

      antirice    
      The first rule of Perl club is - use Perl
      The
      ith rule of Perl club is - follow rule i - 1 for i > 1