From: Vincent Pit Date: Mon, 16 Aug 2010 13:09:38 +0000 (+0200) Subject: Allow /^:?fatal$/ to specify the lethal behaviour X-Git-Tag: rt59498 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=264cfc06a5a9413b36340441e4e34de4a413c341;p=perl%2Fmodules%2Findirect.git Allow /^:?fatal$/ to specify the lethal behaviour This fixes RT #59498. --- diff --git a/lib/indirect.pm b/lib/indirect.pm index 239773f..6cdf32a 100644 --- a/lib/indirect.pm +++ b/lib/indirect.pm @@ -35,7 +35,7 @@ BEGIN { } try { ... }; # warns - no indirect ':fatal'; + no indirect ':fatal'; # or 'FATAL', or ':Fatal' ... if (defied $foo) { ... } # croaks, note the typo # From the command-line @@ -72,7 +72,7 @@ BEGIN { =head1 METHODS -=head2 C<< unimport [ hook => $hook | ':fatal' ] >> +=head2 C<< unimport [ hook => $hook | ':fatal', 'FATAL', ... ] >> Magically called when C is encountered. Turns the module on. @@ -82,7 +82,7 @@ The policy to apply depends on what is first found in C<@opts> : =item * -If it's the string C<':fatal'>, the compilation will croak on the first indirect syntax met. +If it is a string that matches C, the compilation will croak on the first indirect syntax met. =item * @@ -105,7 +105,7 @@ sub unimport { my $arg = shift; if ($arg eq 'hook') { $hook = shift; - } elsif ($arg eq ':fatal') { + } elsif ($arg =~ /^:?fatal$/i) { $hook = sub { die msg(@_) }; } last if $hook; diff --git a/t/10-args.t b/t/10-args.t index 4037c60..bacf850 100644 --- a/t/10-args.t +++ b/t/10-args.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 4 + 1 + 1; +use Test::More tests => 4 + 3 + 1; BEGIN { delete $ENV{PERL_INDIRECT_PM_DISABLE} } @@ -31,17 +31,17 @@ sub expect { is_deeply \@warns, [ ], 'no more warnings without arguments'; } -{ +for my $fatal (':fatal', 'FATAL', ':Fatal') { { local $SIG{__WARN__} = sub { die "warn:@_" }; - eval <<' HERE'; + eval <<" HERE"; die qq{shouldn't even compile\n}; - no indirect ':fatal', hook => sub { die 'should not be called' }; - my $x = new Croaked; - $x = new NotReached; + no indirect '$fatal', hook => sub { die 'should not be called' }; + my \$x = new Croaked; + \$x = new NotReached; HERE } - like $@, expect('Croaked'), 'croaks when :fatal is specified'; + like $@, expect('Croaked'), "croaks when $fatal is specified"; } {