Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Strict CPAN distribution.

Report information
The Basics
Id: 59525
Status: open
Priority: 0/
Queue: Test-Strict

People
Owner: Nobody in particular
Requestors: david.tulloh [...] AirservicesAustralia.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.14
Fixed in: (no value)



Subject: Wishlist: Make strict_ok actually check for strictness rather than regex
The use strict test works by searching the Perl code for "use strict". This is seriously limited, shown by the additional searching for "use Moose" and "use Mouse". I ran into this because I have adopted "use Modern::Perl" for my code, this also sets strict for me. I suggest that the current approach of parsing the perl code is flawed. It works for the most common case. It doesn't catch if strict is only partially enabled or later disabled. What's worse it doesn't always catch if it's been commented out "use warnings; # use strict;" As an alternative approach may I suggest probing the $^H variable? This is messy due to scope issues but I believe is possible. A one line proof of concept is: echo 'BEGIN {say $^H & 0x602}' | cat TESTME - | perl A more complete example follows. I have tried to make it cross platform. It still has some rough edges, if you are interested I will probably have them fixed in a few days. use Test::Builder; use autodie ':all'; use File::Temp; sub real_strict_ok { my ($filename, $msg) = @_; $msg //= "Strict really set for $filename"; my $Test = Test::Builder->new; # Singleton my $tmp = File::Temp->new(); # TODO: Handle multiple packages { open (my $in_fh, "<", $filename); local ($/); my $text = <$in_fh>; print $tmp $text, ";"; # Add trailing ; in case they left it off # 0x602 is strict refs, subs, vars. Obtained from strict.pm. say $tmp 'BEGIN {print(($^H & 0x602) == 0x602, "\n")}'; } # TODO: Capture STDERR my $result = [split /\n/, `$^X -c $tmp`]->[-1]; $Test->ok($result, $msg); }
Here's another case where simply looking for "use strict" is not enough: use v5.18.0; # turns on strict