=cut
BEGIN {
- require XSLoader;
- XSLoader::load(__PACKAGE__, $VERSION);
+ if ($ENV{PERL_INDIRECT_PM_DISABLE}) {
+ *_tag = sub ($) { 1 };
+ } else {
+ require XSLoader;
+ XSLoader::load(__PACKAGE__, $VERSION);
+ }
}
=head1 METHODS
The default warning/exception message thrown when an indirect call on a block is found.
+=head1 ENVIRONMENT
+
+=head2 C<PERL_INDIRECT_PM_DISABLE>
+
+If this environment variable is set to true when the pragma is used for the first time, the XS code won't be loaded and, although the C<'indirect'> lexical hint will be set to true in the scope of use, the pragma itself won't do anything.
+This is useful for disabling C<indirect> in production environments.
+
+Note that clearing this variable after C<indirect> was loaded has no effect.
+If you want to reenable the pragma later, you also need to reload it by deleting the C<'indirect.pm'> entry from C<%INC>.
+
=head1 CAVEATS
The implementation was tweaked to work around several limitations of vanilla C<perl> pragmas : it's thread safe, and doesn't suffer from a C<perl 5.8.x-5.10.0> bug that causes all pragmas to propagate into C<require>d scopes.
--- /dev/null
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+
+{
+ local $ENV{PERL_INDIRECT_PM_DISABLE} = 1;
+ my $err = 0;
+ my $res = eval <<' TEST_ENV_VARIABLE';
+ return 1;
+ no indirect hook => sub { ++$err };
+ my $x = new Flurbz;
+ TEST_ENV_VARIABLE
+ is $@, '', 'PERL_INDIRECT_PM_DISABLE test doesn\'t croak';
+ is $res, 1, 'PERL_INDIRECT_PM_DISABLE test returns the correct value';
+ is $err, 0, 'PERL_INDIRECT_PM_DISABLE test didn\'t generate any error';
+}