Subject: | 'use Moose::Autobox' has no difference from 'use Moose' for strict_ok |
Hello.
It is known that 'use Moose' turns on strictures. 'Test::Strict' is known to
check for it.
On the other side, the 'use Moose::Autobox' may happen to be included
into the
checked source(s) by a mistake. It happens that 'Test::Strict' doesn't
distinct such a situation with the perfect absence of the 'use Moose' or
any other kind of strictures.
The patch supplied solves the problem for me. Below is the shell session
example showing the issue.
Thank you.
===
$ perl -e 'use Moose::Autobox; $abcd = "efgh";'
$ perl -Mstrict -e 'use Moose::Autobox; $abcd;'
Global symbol "$abcd" requires explicit package name at -e line 1.
Execution of -e aborted due to compilation errors.
$ echo 'use Moose::Autobox; $abcd;' > test00.pl
$ perl -Mstrict -we 'use Test::Strict qw{tests 1};
strict_ok( "test00.pl" );'
1..1
ok 1 - use strict test00.pl
Subject: | Test-Strict-2013-02-17-02.patch |
diff -ru Test-Strict-0.17.orig/lib/Test/Strict.pm Test-Strict-0.17/lib/Test/Strict.pm
--- Test-Strict-0.17.orig/lib/Test/Strict.pm 2012-12-30 10:14:07.000000000 +0400
+++ Test-Strict-0.17/lib/Test/Strict.pm 2013-02-17 12:54:19.000000000 +0400
@@ -215,7 +215,7 @@
next if (/^\s*=.+/ .. /^\s*=(cut|back|end)/); # Skip pod
last if (/^\s*(__END__|__DATA__)/); # End of code
if ( /\buse\s+strict\s*;/
- or /\buse\s+Moose\b/
+ or /\buse\s+Moose(?:[^\w:]|$)/
or /\buse\s+Mouse\b/
or /\buse\s+Modern::Perl\b/
) {
diff -ru Test-Strict-0.17.orig/t/02fail.t Test-Strict-0.17/t/02fail.t
--- Test-Strict-0.17.orig/t/02fail.t 2010-02-14 03:50:01.000000000 +0300
+++ Test-Strict-0.17/t/02fail.t 2013-02-17 12:52:33.000000000 +0400
@@ -17,7 +17,7 @@
}
}
-use Test::More tests => 10;
+use Test::More tests => 13;
use File::Temp qw( tempdir tempfile );
my $perl = $^X || 'perl';
@@ -28,6 +28,7 @@
test2();
test3();
test4();
+test5();
exit;
@@ -70,6 +71,16 @@
like( $content, qr/not ok \d+ \- use warnings/, "Does not have use warnings" );
}
+sub test5 {
+ my $dir = make_moose_bad_file();
+ my ($fh, $outfile) = tempfile( UNLINK => 1 );
+ ok( `$perl $inc -MTest::Strict -e "all_perl_files_ok( '$dir' )" 2>&1 > $outfile` );
+ local $/ = undef;
+ my $content = <$fh>;
+ like( $content, qr/^ok 1 - Syntax check /m, "Syntax ok" );
+ like( $content, qr/not ok 2 - use strict /, "Does not have use strict" );
+}
+
sub make_bad_file {
my $tmpdir = tempdir( CLEANUP => 1 );
@@ -106,6 +117,17 @@
return $tmpdir;
}
+sub make_moose_bad_file {
+ my $tmpdir = tempdir( CLEANUP => 1 );
+ my ($fh, $filename) = tempfile( DIR => $tmpdir, SUFFIX => '.pm' );
+ print $fh <<'DUMMY';
+# Makes methods for plain Perl types with autobox
+# No 'use Moose' here and no strictures turned on
+use Moose::Autobox;
+DUMMY
+ return $tmpdir;
+}
+
sub make_bad_warning {
my $tmpdir = tempdir( CLEANUP => 1 );
Only in Test-Strict-0.17/t: 02fail.t.orig