Acme::use::strict::with::pride - enforce bondage and discipline on very


Acme-use-strict-with-pride documentation Contained in the Acme-use-strict-with-pride distribution.

Index


Code Index:

NAME

Top

Acme::use::strict::with::pride - enforce bondage and discipline on very naughty modules.

SYNOPSIS

Top

  use Acme::use::strict::with::pride;
  # now all your naughty modules get to use strict; and use warnings;

ABSTRACT

Top

using Acme::use::strict::with::pride causes all modules to run with use strict; and use warnings;

Whether they like it or not :-)

DESCRIPTION

Top

Acme::use::strict::with::pride installs a code reference into @INC that intercepts all future use and require requests. (code references in @INC were in 5.6.x, but were not documented until 5.8.0, which extends the feature to allow objects in @INC).

The subroutine in @INC then finds the module using the normal @INC path, opens the file, and attaches a source filter that adds "use strict; use warnings;" to the start of every file. This is naughty - it's not a documented feature, it may be changed or removed with no notice, and the current implementation is slightly buggy in subtle cases.

EXPORT

Nothing. There's no unimport method, so using strict with pride is a one way trip. This could be construed as a bug or a feature, depending on your point of view.

SEE ALSO

Top

strict warnings Acme::USIG

BUGS

Top

There's no unimport. There's no way to specify an import list to use strict; or use warnings;. There's no way to exclude specific modules (eg Exporter) from the clutches Acme::use::strict:with::pride. The error and warning handling is global, rather than being chained, and it won't play nicely with error objects. The source filter in coderef @INC is undocumented, so I shouldn't be using it.

AUTHOR

Top

Nicholas Clark, <nick@talking.bollo.cx>

COPYRIGHT AND LICENSE

Top


Acme-use-strict-with-pride documentation Contained in the Acme-use-strict-with-pride distribution.

package Acme::use::strict::with::pride;

use 5.006;
use strict;
use warnings;

our $VERSION = '0.04';

our $script;

sub import {
  # OK. This is a big hack. I'm going to ignore any arguments.
  unshift @INC, sub {
    my ($self, $file) = @_;
    foreach my $dir (@INC) {
      next if ref $dir;
      my $full = "$dir/$file";
      if (open my $fh, "<", $full) {
	# Dave made us do this too:
	my @lines = ("use strict; use warnings;\n", "#line 1 \"$full\"\n");
	# You didn't see this:
	return ($fh, sub {
	  # We really ought to (a) document or rescind this feature
	  # (b) if we document it, change the implementation to use filter
	  # simple
	  # (c) if so, check whether it falls foul of the subtle trap of
	  # caller-filter leaves some data in the buffer, and filter gets to see
	  # it in $_ for a second time.
	  if (@lines) {
	    push @lines, $_;
	    $_ = shift @lines;
	    return length $_;
	  }
	  return 0;
	});
      }
    }
    return;
  }
};

1;
__END__