strictures-2.000002/000755 000765 000024 00000000000 12616512072 014427 5ustar00gknopstaff000000 000000 strictures-2.000002/Changes000644 000765 000024 00000006057 12616512052 015730 0ustar00gknopstaff000000 000000 Release history for strictures 2.000002 - 2015-11-04 - use ExtUtils::HasCompiler to detect compiler rather than ExtUtils::CBuilder - more comprehensive testing 2.000001 - 2015-06-28 - update for perl 5.22 warning categories - avoid using goto &UNIVERSAL::VERSION on perl 5.8, since it segfaults some builds - also detect development directories based on .bzr directory - various test cleanups 2.000000 - 2015-02-26 * Incompatible Changes - strictures 2 fatalizes only a subset of warnings. Some warning categories are not safe to catch, or just inappropriate to have fatal. Existing code looking like 'use strictures 1;' will continue to get the old behavior of fatalizing all errors. The new behavior will take effect when no version or version 2 is specified. 1.005006 - 2015-01-30 - fix extra checks triggering on paths starting with t, xt, lib, or blib, rather than only triggering on those directories. - avoid stat checks for VCS directories until we are in an appropriately named file - various cleanups in test files 1.005005 - 2014-08-16 - include minimum perl version in metadata 1.005004 - 2014-03-06 - make sure meta files list extra modules as recommendations, not requirements 1.005003 - 2014-02-12 - added support for PUREPERL_ONLY (rt#91407) - fixed using strictures->VERSION to query the version (rt#92965) 1.005002 - 2013-12-10 - extra prereqs will be listed as hard prerequisites if a compiler is available 1.005001 - 2013-11-07 - fix skip on old perl on test script 1.005000 - 2013-11-05 - detect mercurial when checking for development trees - avoid using constant.pm to save a bit of memory on older perls - update to v2 metadata 1.004004 - 2012-11-12 - fix crash in 1.004003 due to qw() list being readonly 1.004003 - 2012-11-10 - check only once for presence of extra testing prereqs - explicitly specify no dynamic_config in META 1.004002 - 2012-09-08 - add better rationale for the extra testing heuristic 1.004001 - 2012-07-12 - test-specific strictures now enabled during 'dzil test' 1.004000 - 2012-07-12 - switch to testing calling file to avoid firing on dependencies 1.003001 - 2012-04-08 - fix test to handle defatalization 1.003000 - 2012-04-07 - try and run for any checkout t/ now we don't blow up the process - defatalize lack of extra testing modules - disable extra tests on perls <= 5.008003, things do not work there as expected 1.002002 - 2011-02-25 - only try and mkdir the .git if it doesn't already exist so repeated test runs don't explode 1.002001 - 2011-02-25 - switch .svn to .git in smells-of-vcs test and create it ourselves to ease importing of this dist into subversion repositories 1.002000 - 2011-02-16 - add multidimensional and bareword::filehandles in author mode 1.1.1 - 2010-12-05 - disable uninitialized warnings before calling ->SUPER::VERSION 1.1.0 - 2010-11-22 - enable extra testing only if .git or .svn present to keep requirement for extra modules author-side 1.0.0 - 2010-07-18 - initial release strictures-2.000002/inc/000755 000765 000024 00000000000 12616512072 015200 5ustar00gknopstaff000000 000000 strictures-2.000002/lib/000755 000765 000024 00000000000 12616512072 015175 5ustar00gknopstaff000000 000000 strictures-2.000002/maint/000755 000765 000024 00000000000 12616512072 015537 5ustar00gknopstaff000000 000000 strictures-2.000002/Makefile.PL000644 000765 000024 00000006445 12613736642 016422 0ustar00gknopstaff000000 000000 use strict; use warnings FATAL => 'all'; use 5.006; require "inc/ExtUtils/HasCompiler.pm"; my $have_compiler = ! parse_args()->{PUREPERL_ONLY} && ExtUtils::HasCompiler::can_compile_loadable_object(quiet => 1); my %extra_prereqs = ( indirect => 0, multidimensional => 0, 'bareword::filehandles' => 0, ); my %META = ( name => 'strictures', license => 'perl_5', prereqs => { configure => { requires => { } }, build => { requires => { } }, test => { requires => { 'Test::More' => 0, } }, runtime => { requires => { perl => '5.006', }, recommends => { %extra_prereqs, }, }, develop => { requires => { 'Test::Pod' => 0, 'Test::Pod::Coverage' => 0, 'Pod::Coverage::CountParents' => 0, %extra_prereqs, } }, }, resources => { # r/w: p5sagit@git.shadowcat.co.uk:strictures.git repository => { url => 'git://git.shadowcat.co.uk/p5sagit/strictures.git', web => 'http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/strictures.git', type => 'git', }, bugtracker => { mailto => 'bug-strictures@rt.cpan.org', web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=strictures', }, license => [ 'http://dev.perl.org/licenses/' ], }, no_index => { directory => [ 't', 'xt' ] }, ); my %MM_ARGS = ( PREREQ_PM => { ($] >= 5.008004 && $have_compiler ? %extra_prereqs : () ) }, ); sub parse_args { # copied from EUMM require ExtUtils::MakeMaker; require Text::ParseWords; ExtUtils::MakeMaker::parse_args( my $tmp = {}, Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''), @ARGV, ); return $tmp->{ARGS} || {}; } ## BOILERPLATE ############################################################### require ExtUtils::MakeMaker; (do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml'; # have to do this since old EUMM dev releases miss the eval $VERSION line my $eumm_version = eval $ExtUtils::MakeMaker::VERSION; my $mymeta = $eumm_version >= 6.57_02; my $mymeta_broken = $mymeta && $eumm_version < 6.57_07; ($MM_ARGS{NAME} = $META{name}) =~ s/-/::/g; ($MM_ARGS{VERSION_FROM} = "lib/$MM_ARGS{NAME}.pm") =~ s{::}{/}g; $META{license} = [ $META{license} ] if $META{license} && !ref $META{license}; $MM_ARGS{LICENSE} = $META{license}[0] if $META{license} && $eumm_version >= 6.30; $MM_ARGS{NO_MYMETA} = 1 if $mymeta_broken; $MM_ARGS{META_ADD} = { 'meta-spec' => { version => 2 }, %META } unless -f 'META.yml'; for (qw(configure build test runtime)) { my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES'; my $r = $MM_ARGS{$key} = { %{$META{prereqs}{$_}{requires} || {}}, %{delete $MM_ARGS{$key} || {}}, }; defined $r->{$_} or delete $r->{$_} for keys %$r; } $MM_ARGS{MIN_PERL_VERSION} = delete $MM_ARGS{PREREQ_PM}{perl} || 0; delete $MM_ARGS{MIN_PERL_VERSION} if $eumm_version < 6.47_01; $MM_ARGS{BUILD_REQUIRES} = {%{$MM_ARGS{BUILD_REQUIRES}}, %{delete $MM_ARGS{TEST_REQUIRES}}} if $eumm_version < 6.63_03; $MM_ARGS{PREREQ_PM} = {%{$MM_ARGS{PREREQ_PM}}, %{delete $MM_ARGS{BUILD_REQUIRES}}} if $eumm_version < 6.55_01; delete $MM_ARGS{CONFIGURE_REQUIRES} if $eumm_version < 6.51_03; ExtUtils::MakeMaker::WriteMakefile(%MM_ARGS); ## END BOILERPLATE ########################################################### strictures-2.000002/MANIFEST000644 000765 000024 00000000702 12616512072 015557 0ustar00gknopstaff000000 000000 Changes inc/ExtUtils/HasCompiler.pm lib/strictures.pm lib/strictures/extra.pm maint/Makefile.PL.include Makefile.PL MANIFEST This list of files t/crash.t t/extras.t t/strictures.t xt/all-categories.t xt/pod.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) README README file (added by Distar) strictures-2.000002/META.json000644 000765 000024 00000003433 12616512072 016053 0ustar00gknopstaff000000 000000 { "abstract" : "turn on strict and make most warnings fatal", "author" : [ "mst - Matt S. Trout (cpan:MSTROUT) " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150001", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "strictures", "no_index" : { "directory" : [ "t", "xt" ] }, "prereqs" : { "build" : { "requires" : {} }, "configure" : { "requires" : {} }, "develop" : { "requires" : { "Pod::Coverage::CountParents" : "0", "Test::Pod" : "0", "Test::Pod::Coverage" : "0", "bareword::filehandles" : "0", "indirect" : "0", "multidimensional" : "0" } }, "runtime" : { "recommends" : { "bareword::filehandles" : "0", "indirect" : "0", "multidimensional" : "0" }, "requires" : { "perl" : "5.006" } }, "test" : { "requires" : { "Test::More" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-strictures@rt.cpan.org", "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=strictures" }, "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://git.shadowcat.co.uk/p5sagit/strictures.git", "web" : "http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/strictures.git" } }, "version" : "2.000002" } strictures-2.000002/META.yml000644 000765 000024 00000001405 12616512072 015700 0ustar00gknopstaff000000 000000 --- abstract: 'turn on strict and make most warnings fatal' author: - 'mst - Matt S. Trout (cpan:MSTROUT) ' build_requires: Test::More: '0' configure_requires: {} dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150001' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: strictures no_index: directory: - t - xt recommends: bareword::filehandles: '0' indirect: '0' multidimensional: '0' requires: perl: '5.006' resources: bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=strictures license: http://dev.perl.org/licenses/ repository: git://git.shadowcat.co.uk/p5sagit/strictures.git version: '2.000002' strictures-2.000002/README000644 000765 000024 00000022445 12616512072 015316 0ustar00gknopstaff000000 000000 NAME strictures - turn on strict and make most warnings fatal SYNOPSIS use strictures 2; is equivalent to use strict; use warnings FATAL => 'all'; use warnings NONFATAL => qw( exec recursion internal malloc newline experimental deprecated portable ); no warnings 'once'; except when called from a file which matches: (caller)[1] =~ /^(?:t|xt|lib|blib)[\\\/]/ and when either ".git", ".svn", ".hg", or ".bzr" is present in the current directory (with the intention of only forcing extra tests on the author side) -- or when ".git", ".svn", ".hg", or ".bzr" is present two directories up along with "dist.ini" (which would indicate we are in a "dzil test" operation, via Dist::Zilla) -- or when the "PERL_STRICTURES_EXTRA" environment variable is set, in which case it also does the equivalent of no indirect 'fatal'; no multidimensional; no bareword::filehandles; Note that "PERL_STRICTURES_EXTRA" may at some point add even more tests, with only a minor version increase, but any changes to the effect of "use strictures" in normal mode will involve a major version bump. If any of the extra testing modules are not present, strictures will complain loudly, once, via "warn()", and then shut up. But you really should consider installing them, they're all great anti-footgun tools. DESCRIPTION I've been writing the equivalent of this module at the top of my code for about a year now. I figured it was time to make it shorter. Things like the importer in "use Moose" don't help me because they turn warnings on but don't make them fatal -- which from my point of view is useless because I want an exception to tell me my code isn't warnings-clean. Any time I see a warning from my code, that indicates a mistake. Any time my code encounters a mistake, I want a crash -- not spew to STDERR and then unknown (and probably undesired) subsequent behaviour. I also want to ensure that obvious coding mistakes, like indirect object syntax (and not so obvious mistakes that cause things to accidentally compile as such) get caught, but not at the cost of an XS dependency and not at the cost of blowing things up on another machine. Therefore, strictures turns on additional checking, but only when it thinks it's running in a test file in a VCS checkout -- although if this causes undesired behaviour this can be overridden by setting the "PERL_STRICTURES_EXTRA" environment variable. If additional useful author side checks come to mind, I'll add them to the "PERL_STRICTURES_EXTRA" code path only -- this will result in a minor version increase (e.g. 1.000000 to 1.001000 (1.1.0) or similar). Any fixes only to the mechanism of this code will result in a sub-version increase (e.g. 1.000000 to 1.000001 (1.0.1)). CATEGORY SELECTIONS strictures does not enable fatal warnings for all categories. exec Includes a warning that can cause your program to continue running unintentionally after an internal fork. Not safe to fatalize. recursion Infinite recursion will end up overflowing the stack eventually anyway. internal Triggers deep within perl, in places that are not safe to trap. malloc Triggers deep within perl, in places that are not safe to trap. newline Includes a warning for using stat on a valid but suspect filename, ending in a newline. experimental Experimental features are used intentionally. deprecated Deprecations will inherently be added to in the future in unexpected ways, so making them fatal won't be reliable. portable Doesn't indicate an actual problem with the program, only that it may not behave properly if run on a different machine. once Can't be fatalized. Also triggers very inconsistently, so we just disable it. VERSIONS Depending on the version of strictures requested, different warnings will be enabled. If no specific version is requested, the current version's behavior will be used. Versions can be requested using perl's standard mechanism: use strictures 2; Or, by passing in a "version" option: use strictures version => 2; VERSION 2 Equivalent to: use strict; use warnings FATAL => 'all'; use warnings NONFATAL => qw( exec recursion internal malloc newline experimental deprecated portable ); no warnings 'once'; # and if in dev mode: no indirect 'fatal'; no multidimensional; no bareword::filehandles; Additionally, any warnings created by modules using warnings::register or "warnings::register_categories()" will not be fatalized. VERSION 1 Equivalent to: use strict; use warnings FATAL => 'all'; # and if in dev mode: no indirect 'fatal'; no multidimensional; no bareword::filehandles; METHODS import This method does the setup work described above in "DESCRIPTION". Optionally accepts a "version" option to request a specific version's behavior. VERSION This method traps the "strictures->VERSION(1)" call produced by a use line with a version number on it and does the version check. EXTRA TESTING RATIONALE Every so often, somebody complains that they're deploying via "git pull" and that they don't want strictures to enable itself in this case -- and that setting "PERL_STRICTURES_EXTRA" to 0 isn't acceptable (additional ways to disable extra testing would be welcome but the discussion never seems to get that far). In order to allow us to skip a couple of stages and get straight to a productive conversation, here's my current rationale for turning the extra testing on via a heuristic: The extra testing is all stuff that only ever blows up at compile time; this is intentional. So the oft-raised concern that it's different code being tested is only sort of the case -- none of the modules involved affect the final optree to my knowledge, so the author gets some additional compile time crashes which he/she then fixes, and the rest of the testing is completely valid for all environments. The point of the extra testing -- especially "no indirect" -- is to catch mistakes that newbie users won't even realise are mistakes without help. For example, foo { ... }; where foo is an & prototyped sub that you forgot to import -- this is pernicious to track down since all *seems* fine until it gets called and you get a crash. Worse still, you can fail to have imported it due to a circular require, at which point you have a load order dependent bug which I've seen before now *only* show up in production due to tiny differences between the production and the development environment. I wrote to explain this particular problem before strictures itself existed. As such, in my experience so far strictures' extra testing has *avoided* production versus development differences, not caused them. Additionally, strictures' policy is very much "try and provide as much protection as possible for newbies -- who won't think about whether there's an option to turn on or not" -- so having only the environment variable is not sufficient to achieve that (I get to explain that you need to add "use strict" at least once a week on freenode #perl -- newbies sometimes completely skip steps because they don't understand that that step is important). I make no claims that the heuristic is perfect -- it's already been evolved significantly over time, especially for 1.004 where we changed things to ensure it only fires on files in your checkout (rather than strictures-using modules you happened to have installed, which was just silly). However, I hope the above clarifies why a heuristic approach is not only necessary but desirable from a point of view of providing new users with as much safety as possible, and will allow any future discussion on the subject to focus on "how do we minimise annoyance to people deploying from checkouts intentionally". SEE ALSO * indirect * multidimensional * bareword::filehandles COMMUNITY AND SUPPORT IRC channel irc.perl.org #toolchain (or bug 'mst' in query on there or freenode) Git repository Gitweb is on http://git.shadowcat.co.uk/ and the clone URL is: git clone git://git.shadowcat.co.uk/p5sagit/strictures.git The web interface to the repository is at: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/strictures.git AUTHOR mst - Matt S. Trout (cpan:MSTROUT) CONTRIBUTORS Karen Etheridge (cpan:ETHER) Mithaldu - Christian Walde (cpan:MITHALDU) haarg - Graham Knop (cpan:HAARG) COPYRIGHT Copyright (c) 2010 the strictures "AUTHOR" and "CONTRIBUTORS" as listed above. LICENSE This library is free software and may be distributed under the same terms as perl itself. strictures-2.000002/t/000755 000765 000024 00000000000 12616512072 014672 5ustar00gknopstaff000000 000000 strictures-2.000002/xt/000755 000765 000024 00000000000 12616512072 015062 5ustar00gknopstaff000000 000000 strictures-2.000002/xt/all-categories.t000644 000765 000024 00000002021 12463506517 020144 0ustar00gknopstaff000000 000000 BEGIN { if (keys %INC) { print "1..0 # SKIP can't test categories with additional modules loaded\n"; exit 0; } } use strict; use warnings; BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0 } use strictures (); # avoid loading Test::More, since it adds warning categories my %known_cats; @known_cats{@strictures::WARNING_CATEGORIES} = (); my %core_cats; @core_cats{grep ! /^(?:all|everything|extra)$/, keys %warnings::Offsets} = (); my @missing = sort grep { !exists $known_cats{$_} } keys %core_cats; my @extra = sort grep { !exists $core_cats{$_} } keys %known_cats; print "1..2\n"; print((@missing ? 'not ' : '') . "ok 1 - strictures includes all warning categories\n"); if (@missing) { print STDERR "# strictures is missing categories:\n"; print STDERR "# $_\n" for @missing; } print((@extra ? 'not ' : '') . "ok 2 - strictures includes no extra categories\n"); if (@extra) { print STDERR "# strictures lists extra categories:\n"; print STDERR "# $_\n" for @extra; } if (@missing || @extra) { exit 1; } strictures-2.000002/xt/pod.t000644 000765 000024 00000000362 12462672050 016034 0ustar00gknopstaff000000 000000 use Test::More; use Test::Pod; use Test::Pod::Coverage; use strict; use warnings FATAL => 'all'; pod_file_ok($_) for all_pod_files; pod_coverage_ok($_, { coverage_class => 'Pod::Coverage::CountParents' }) for all_modules; done_testing; strictures-2.000002/t/crash.t000644 000765 000024 00000001177 12463506517 016174 0ustar00gknopstaff000000 000000 use strict; use warnings FATAL => 'all'; use Test::More $] < 5.008004 ? ( skip_all => "can't test extra loading on perl < 5.8.4" ) : ( tests => 1 ); use File::Spec; my %extras = map { my $m = "$_.pm"; $m =~ s{::}{/}g; $m => 1 } qw( indirect multidimensional bareword::filehandles ); unshift @INC, sub { my $mod = $_[1]; die "Can't locate $mod in \@INC\n" if $extras{$mod}; return 0; }; my $err = do { local $ENV{PERL_STRICTURES_EXTRA} = 1; local *STDERR; open STDERR, '>', File::Spec->devnull; eval q{use strictures;}; $@; }; is $err, '', 'can manage to survive with some modules missing!'; strictures-2.000002/t/extras.t000644 000765 000024 00000005574 12616244646 016411 0ustar00gknopstaff000000 000000 BEGIN { delete $ENV{PERL_STRICTURES_EXTRA} } use strict; use warnings; use Test::More $] >= 5.008_004 ? qw(no_plan) : (skip_all => 'Extra tests disabled on perls <= 5.008003'); use File::Temp; use Cwd 'cwd'; my %extras; BEGIN { %extras = map { $_ => 1 } qw( indirect.pm multidimensional.pm bareword/filehandles.pm ); $INC{$_} = __FILE__ for keys %extras; } use strictures (); my $indirect = 0; sub indirect::unimport { $indirect++; }; my $cwd = cwd; for my $version ( 1, 2 ) { my $tempdir = File::Temp::tempdir('strictures-XXXXXX', CLEANUP => 1, TMPDIR => 1); chdir $tempdir; local $strictures::Smells_Like_VCS = undef; eval qq{ #line 1 "t/nogit.t" use strictures $version; 1; } or die "$@"; ok defined $strictures::Smells_Like_VCS, "VCS dir has been checked (v$version)"; ok !$strictures::Smells_Like_VCS, "VCS dir not detected with no .git (v$version)"; mkdir '.git'; { local $strictures::Smells_Like_VCS = undef; eval qq{ #line 1 "t/withgit.t" use strictures $version; 1; } or die "$@"; ok defined $strictures::Smells_Like_VCS, "VCS dir has been checked (v$version)"; ok $strictures::Smells_Like_VCS, "VCS dir detected with .git (v$version)"; } chdir $cwd; rmdir $tempdir; local $strictures::Smells_Like_VCS = 1; for my $check ( ["file.pl" => 0], ["test.pl" => 0], ["library.pm" => 0], ["t/test.t" => 1], ["xt/test.t" => 1], ["t/one.faket" => 1], ["lib/module.pm" => 1], ["other/one.pl" => 0], ["other/t/test.t" => 0], ["blib/module.pm" => 1], ) { my ($file, $want) = @$check; $indirect = 0; eval qq{ #line 1 "$file" use strictures $version; 1; } or die "$@"; my $not = $want ? '' : ' not'; is $indirect, $want, "file named $file does$not get extras (v$version)"; } { local $ENV{PERL_STRICTURES_EXTRA} = 1; local %strictures::extra_load_states = (); local @INC = (sub { die "Can't locate $_[1] in \@INC (...).\n" if $extras{$_[1]}; }, @INC); local %INC = %INC; delete $INC{$_} for keys %extras; { open my $fh, '>', \(my $str = ''); my $e; { local *STDERR = $fh; eval qq{ #line 1 "t/load_fail.t" use strictures $version; 1; } or $e = "$@"; } die $e if defined $e; like( $str, qr/Missing were:\n\n indirect multidimensional bareword::filehandles/, "failure to load all three extra deps is reported (v$version)" ); } { open my $fh, '>', \(my $str = ''); my $e; { local *STDERR = $fh; eval qq{ #line 1 "t/load_fail.t" use strictures $version; 1; } or $e = "$@"; } die $e if defined $e; is $str, '', "extra dep load failure is not reported a second time (v$version)"; } } } strictures-2.000002/t/strictures.t000644 000765 000024 00000003562 12616244646 017305 0ustar00gknopstaff000000 000000 BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0 } sub _eval { eval $_[0] } use strict; use warnings; use Test::More qw(no_plan); sub capture_hints { my $code = shift; $code .= q{ ; my @h; BEGIN { @h = ( $^H, ${^WARNING_BITS} ) } @h; }; my ($hints, $warning_bits) = _eval $code or die $@; # ignore lexicalized hints $hints &= ~ 0x20000; $warning_bits = unpack "H*", $warning_bits if defined $warning_bits; return ($hints, $warning_bits); } sub compare_hints { my ($code_want, $code_got, $name) = @_; my ($want_hints, $want_warnings) = capture_hints $code_want; my ($hints, $warnings) = capture_hints $code_got; is($hints, $want_hints, "Hints correct for $name"); is($warnings, $want_warnings, "Warnings correct for $name"); } compare_hints q{ use strict; use warnings FATAL => 'all'; }, q{ use strictures 1; }, 'version 1'; compare_hints q{ use strict; use warnings 'all'; use warnings FATAL => @strictures::WARNING_CATEGORIES; no warnings FATAL => @strictures::V2_NONFATAL; use warnings @strictures::V2_NONFATAL; no warnings @strictures::V2_DISABLE; }, q{ use strictures 2; }, 'version 2'; my $v; eval { $v = strictures->VERSION; 1 } or diag $@; is $v, $strictures::VERSION, '->VERSION returns version correctly'; my $next = int $strictures::VERSION + 1; eval qq{ use strictures $next; }; like $@, qr/strictures version $next required/, "Can't use strictures $next (this is version $v)"; eval qq{ use strictures {version => $next}; }; like $@, qr/Major version specified as $next - not supported/, "Can't use strictures version option $next (this is version $v)"; eval qq{ use strictures {version => undef}; }; like $@, qr/Major version specified as undef - not supported/, "Can't use strictures version option undef"; eval qq{ use strictures $strictures::VERSION; }; is $@, '', "Can use current strictures version"; strictures-2.000002/maint/Makefile.PL.include000644 000765 000024 00000000344 12613736540 021141 0ustar00gknopstaff000000 000000 BEGIN { -e 'Distar' or system("git clone git://git.shadowcat.co.uk/p5sagit/Distar.git") } use lib 'Distar/lib'; use Distar; author 'mst - Matt S. Trout (cpan:MSTROUT) '; manifest_include inc => '.pm'; 1; strictures-2.000002/lib/strictures/000755 000765 000024 00000000000 12616512072 017404 5ustar00gknopstaff000000 000000 strictures-2.000002/lib/strictures.pm000644 000765 000024 00000034474 12616512044 017755 0ustar00gknopstaff000000 000000 package strictures; use strict; use warnings FATAL => 'all'; BEGIN { *_PERL_LT_5_8_4 = ($] < 5.008004) ? sub(){1} : sub(){0}; # goto &UNIVERSAL::VERSION usually works on 5.8, but fails on some ARM # machines. Seems to always work on 5.10 though. *_CAN_GOTO_VERSION = ($] >= 5.010000) ? sub(){1} : sub(){0}; } our $VERSION = '2.000002'; $VERSION = eval $VERSION; our @WARNING_CATEGORIES = grep { exists $warnings::Offsets{$_} } qw( closure chmod deprecated exiting experimental experimental::autoderef experimental::bitwise experimental::const_attr experimental::lexical_subs experimental::lexical_topic experimental::postderef experimental::re_strict experimental::refaliasing experimental::regex_sets experimental::signatures experimental::smartmatch experimental::win32_perlio glob imprecision io closed exec layer newline pipe syscalls unopened locale misc missing numeric once overflow pack portable recursion redefine redundant regexp severe debugging inplace internal malloc signal substr syntax ambiguous bareword digit illegalproto parenthesis precedence printf prototype qw reserved semicolon taint threads uninitialized umask unpack untie utf8 non_unicode nonchar surrogate void void_unusual y2k ); sub VERSION { { no warnings; local $@; if (defined $_[1] && eval { &UNIVERSAL::VERSION; 1}) { $^H |= 0x20000 unless _PERL_LT_5_8_4; $^H{strictures_enable} = int $_[1]; } } _CAN_GOTO_VERSION ? goto &UNIVERSAL::VERSION : &UNIVERSAL::VERSION; } our %extra_load_states; our $Smells_Like_VCS; sub import { my $class = shift; my %opts = @_ == 1 ? %{$_[0]} : @_; if (!exists $opts{version}) { $opts{version} = exists $^H{strictures_enable} ? delete $^H{strictures_enable} : int $VERSION; } $opts{file} = (caller)[1]; $class->_enable(\%opts); } sub _enable { my ($class, $opts) = @_; my $version = $opts->{version}; $version = 'undef' if !defined $version; my $method = "_enable_$version"; if (!$class->can($method)) { require Carp; Carp::croak("Major version specified as $version - not supported!"); } $class->$method($opts); } sub _enable_1 { my ($class, $opts) = @_; strict->import; warnings->import(FATAL => 'all'); if (_want_extra($opts->{file})) { _load_extras(qw(indirect multidimensional bareword::filehandles)); indirect->unimport(':fatal') if $extra_load_states{indirect}; multidimensional->unimport if $extra_load_states{multidimensional}; bareword::filehandles->unimport if $extra_load_states{'bareword::filehandles'}; } } our @V2_NONFATAL = grep { exists $warnings::Offsets{$_} } ( 'exec', # not safe to catch 'recursion', # will be caught by other mechanisms 'internal', # not safe to catch 'malloc', # not safe to catch 'newline', # stat on nonexistent file with a newline in it 'experimental', # no reason for these to be fatal 'deprecated', # unfortunately can't make these fatal 'portable', # everything worked fine here, just may not elsewhere ); our @V2_DISABLE = grep { exists $warnings::Offsets{$_} } ( 'once' # triggers inconsistently, can't be fatalized ); sub _enable_2 { my ($class, $opts) = @_; strict->import; warnings->import; warnings->import(FATAL => @WARNING_CATEGORIES); warnings->unimport(FATAL => @V2_NONFATAL); warnings->import(@V2_NONFATAL); warnings->unimport(@V2_DISABLE); if (_want_extra($opts->{file})) { _load_extras(qw(indirect multidimensional bareword::filehandles)); indirect->unimport(':fatal') if $extra_load_states{indirect}; multidimensional->unimport if $extra_load_states{multidimensional}; bareword::filehandles->unimport if $extra_load_states{'bareword::filehandles'}; } } sub _want_extra_env { if (exists $ENV{PERL_STRICTURES_EXTRA}) { if (_PERL_LT_5_8_4 and $ENV{PERL_STRICTURES_EXTRA}) { die 'PERL_STRICTURES_EXTRA checks are not available on perls older' . "than 5.8.4: please unset \$ENV{PERL_STRICTURES_EXTRA}\n"; } return $ENV{PERL_STRICTURES_EXTRA} ? 1 : 0; } return undef; } sub _want_extra { my $file = shift; my $want_env = _want_extra_env(); return $want_env if defined $want_env; return ( !_PERL_LT_5_8_4 and $file =~ /^(?:t|xt|lib|blib)[\\\/]/ and defined $Smells_Like_VCS ? $Smells_Like_VCS : ( $Smells_Like_VCS = !!( -e '.git' || -e '.svn' || -e '.hg' || -e '.bzr' || (-e '../../dist.ini' && (-e '../../.git' || -e '../../.svn' || -e '../../.hg' || -e '../../.bzr' )) )) ); } sub _load_extras { my @extras = @_; my @failed; foreach my $mod (@extras) { next if exists $extra_load_states{$mod}; $extra_load_states{$mod} = eval "require $mod; 1;" or do { push @failed, $mod; #work around 5.8 require bug (my $file = $mod) =~ s|::|/|g; delete $INC{"${file}.pm"}; }; } if (@failed) { my $failed = join ' ', @failed; my $extras = join ' ', @extras; print STDERR < 'all'; use warnings NONFATAL => qw( exec recursion internal malloc newline experimental deprecated portable ); no warnings 'once'; except when called from a file which matches: (caller)[1] =~ /^(?:t|xt|lib|blib)[\\\/]/ and when either C<.git>, C<.svn>, C<.hg>, or C<.bzr> is present in the current directory (with the intention of only forcing extra tests on the author side) -- or when C<.git>, C<.svn>, C<.hg>, or C<.bzr> is present two directories up along with C (which would indicate we are in a C operation, via L) -- or when the C environment variable is set, in which case it also does the equivalent of no indirect 'fatal'; no multidimensional; no bareword::filehandles; Note that C may at some point add even more tests, with only a minor version increase, but any changes to the effect of C in normal mode will involve a major version bump. If any of the extra testing modules are not present, L will complain loudly, once, via C, and then shut up. But you really should consider installing them, they're all great anti-footgun tools. =head1 DESCRIPTION I've been writing the equivalent of this module at the top of my code for about a year now. I figured it was time to make it shorter. Things like the importer in C don't help me because they turn warnings on but don't make them fatal -- which from my point of view is useless because I want an exception to tell me my code isn't warnings-clean. Any time I see a warning from my code, that indicates a mistake. Any time my code encounters a mistake, I want a crash -- not spew to STDERR and then unknown (and probably undesired) subsequent behaviour. I also want to ensure that obvious coding mistakes, like indirect object syntax (and not so obvious mistakes that cause things to accidentally compile as such) get caught, but not at the cost of an XS dependency and not at the cost of blowing things up on another machine. Therefore, L turns on additional checking, but only when it thinks it's running in a test file in a VCS checkout -- although if this causes undesired behaviour this can be overridden by setting the C environment variable. If additional useful author side checks come to mind, I'll add them to the C code path only -- this will result in a minor version increase (e.g. 1.000000 to 1.001000 (1.1.0) or similar). Any fixes only to the mechanism of this code will result in a sub-version increase (e.g. 1.000000 to 1.000001 (1.0.1)). =head1 CATEGORY SELECTIONS strictures does not enable fatal warnings for all categories. =over 4 =item exec Includes a warning that can cause your program to continue running unintentionally after an internal fork. Not safe to fatalize. =item recursion Infinite recursion will end up overflowing the stack eventually anyway. =item internal Triggers deep within perl, in places that are not safe to trap. =item malloc Triggers deep within perl, in places that are not safe to trap. =item newline Includes a warning for using stat on a valid but suspect filename, ending in a newline. =item experimental Experimental features are used intentionally. =item deprecated Deprecations will inherently be added to in the future in unexpected ways, so making them fatal won't be reliable. =item portable Doesn't indicate an actual problem with the program, only that it may not behave properly if run on a different machine. =item once Can't be fatalized. Also triggers very inconsistently, so we just disable it. =back =head1 VERSIONS Depending on the version of strictures requested, different warnings will be enabled. If no specific version is requested, the current version's behavior will be used. Versions can be requested using perl's standard mechanism: use strictures 2; Or, by passing in a C option: use strictures version => 2; =head2 VERSION 2 Equivalent to: use strict; use warnings FATAL => 'all'; use warnings NONFATAL => qw( exec recursion internal malloc newline experimental deprecated portable ); no warnings 'once'; # and if in dev mode: no indirect 'fatal'; no multidimensional; no bareword::filehandles; Additionally, any warnings created by modules using L or C will not be fatalized. =head2 VERSION 1 Equivalent to: use strict; use warnings FATAL => 'all'; # and if in dev mode: no indirect 'fatal'; no multidimensional; no bareword::filehandles; =head1 METHODS =head2 import This method does the setup work described above in L. Optionally accepts a C option to request a specific version's behavior. =head2 VERSION This method traps the C<< strictures->VERSION(1) >> call produced by a use line with a version number on it and does the version check. =head1 EXTRA TESTING RATIONALE Every so often, somebody complains that they're deploying via C and that they don't want L to enable itself in this case -- and that setting C to 0 isn't acceptable (additional ways to disable extra testing would be welcome but the discussion never seems to get that far). In order to allow us to skip a couple of stages and get straight to a productive conversation, here's my current rationale for turning the extra testing on via a heuristic: The extra testing is all stuff that only ever blows up at compile time; this is intentional. So the oft-raised concern that it's different code being tested is only sort of the case -- none of the modules involved affect the final optree to my knowledge, so the author gets some additional compile time crashes which he/she then fixes, and the rest of the testing is completely valid for all environments. The point of the extra testing -- especially C -- is to catch mistakes that newbie users won't even realise are mistakes without help. For example, foo { ... }; where foo is an & prototyped sub that you forgot to import -- this is pernicious to track down since all I fine until it gets called and you get a crash. Worse still, you can fail to have imported it due to a circular require, at which point you have a load order dependent bug which I've seen before now I show up in production due to tiny differences between the production and the development environment. I wrote L to explain this particular problem before L itself existed. As such, in my experience so far L' extra testing has I production versus development differences, not caused them. Additionally, L' policy is very much "try and provide as much protection as possible for newbies -- who won't think about whether there's an option to turn on or not" -- so having only the environment variable is not sufficient to achieve that (I get to explain that you need to add C at least once a week on freenode #perl -- newbies sometimes completely skip steps because they don't understand that that step is important). I make no claims that the heuristic is perfect -- it's already been evolved significantly over time, especially for 1.004 where we changed things to ensure it only fires on files in your checkout (rather than L-using modules you happened to have installed, which was just silly). However, I hope the above clarifies why a heuristic approach is not only necessary but desirable from a point of view of providing new users with as much safety as possible, and will allow any future discussion on the subject to focus on "how do we minimise annoyance to people deploying from checkouts intentionally". =head1 SEE ALSO =over 4 =item * L =item * L =item * L =back =head1 COMMUNITY AND SUPPORT =head2 IRC channel irc.perl.org #toolchain (or bug 'mst' in query on there or freenode) =head2 Git repository Gitweb is on http://git.shadowcat.co.uk/ and the clone URL is: git clone git://git.shadowcat.co.uk/p5sagit/strictures.git The web interface to the repository is at: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/strictures.git =head1 AUTHOR mst - Matt S. Trout (cpan:MSTROUT) =head1 CONTRIBUTORS Karen Etheridge (cpan:ETHER) Mithaldu - Christian Walde (cpan:MITHALDU) haarg - Graham Knop (cpan:HAARG) =head1 COPYRIGHT Copyright (c) 2010 the strictures L and L as listed above. =head1 LICENSE This library is free software and may be distributed under the same terms as perl itself. =cut strictures-2.000002/lib/strictures/extra.pm000644 000765 000024 00000001340 12463506517 021072 0ustar00gknopstaff000000 000000 package strictures::extra; use strict; use warnings FATAL => 'all'; sub import { $ENV{PERL_STRICTURES_EXTRA} = 1; } sub unimport { $ENV{PERL_STRICTURES_EXTRA} = 0; } 1; __END__ =head1 NAME strictures::extra - enable or disable strictures additional checks =head1 SYNOPSIS no strictures::extra; # will not enable indirect, multidimensional, or bareword filehandle checks use strictures; =head1 DESCRIPTION Enable or disable strictures additional checks, preventing checks for C<.git> or other VCS directories. Equivalent to setting the C environment variable. =head1 AUTHORS See L for authors. =head1 COPYRIGHT AND LICENSE See L for the copyright and license. =cut strictures-2.000002/inc/ExtUtils/000755 000765 000024 00000000000 12616512072 016761 5ustar00gknopstaff000000 000000 strictures-2.000002/inc/ExtUtils/HasCompiler.pm000644 000765 000024 00000013770 12613736700 021540 0ustar00gknopstaff000000 000000 package ExtUtils::HasCompiler; $ExtUtils::HasCompiler::VERSION = '0.012'; use strict; use warnings; use base 'Exporter'; our @EXPORT_OK = qw/can_compile_loadable_object/; our %EXPORT_TAGS = (all => \@EXPORT_OK); use Config; use Carp 'carp'; use File::Basename 'basename'; use File::Spec::Functions qw/catfile catdir/; use File::Temp qw/tempdir tempfile/; my $tempdir = tempdir(CLEANUP => 1); my $loadable_object_format = <<'END'; #define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #ifndef PERL_UNUSED_VAR #define PERL_UNUSED_VAR(var) #endif XS(exported) { #ifdef dVAR dVAR; #endif dXSARGS; PERL_UNUSED_VAR(cv); /* -W */ PERL_UNUSED_VAR(items); /* -W */ XSRETURN_IV(42); } #ifndef XS_EXTERNAL #define XS_EXTERNAL(foo) XS(foo) #endif /* we don't want to mess with .def files on mingw */ #if defined(WIN32) && defined(__GNUC__) # define EXPORT __declspec(dllexport) #else # define EXPORT #endif EXPORT XS_EXTERNAL(boot_%s) { #ifdef dVAR dVAR; #endif dXSARGS; PERL_UNUSED_VAR(cv); /* -W */ PERL_UNUSED_VAR(items); /* -W */ newXS("%s::exported", exported, __FILE__); } END my $counter = 1; my %prelinking = map { $_ => 1 } qw/MSWin32 VMS aix/; sub can_compile_loadable_object { my %args = @_; my $config = $args{config} || 'ExtUtils::HasCompiler::Config'; return if not $config->get('usedl'); my ($source_handle, $source_name) = tempfile(DIR => $tempdir, SUFFIX => '.c', UNLINK => 1); my $basename = basename($source_name, '.c'); my $shortname = '_Loadable' . $counter++; my $package = "ExtUtils::HasCompiler::$shortname"; printf $source_handle $loadable_object_format, $basename, $package or do { carp "Couldn't write to $source_name: $!"; return }; close $source_handle or do { carp "Couldn't close $source_name: $!"; return }; my $abs_basename = catfile($tempdir, $basename); my $object_file = $abs_basename . $config->get('_o'); my $loadable_object = $abs_basename . '.' . $config->get('dlext'); my $incdir = catdir($config->get('archlibexp'), 'CORE'); my ($cc, $ccflags, $optimize, $cccdlflags, $ld, $ldflags, $lddlflags, $libperl, $perllibs) = map { $config->get($_) } qw/cc ccflags optimize cccdlflags ld ldflags lddlflags libperl perllibs/; if ($prelinking{$^O}) { require ExtUtils::Mksymlists; ExtUtils::Mksymlists::Mksymlists(NAME => $basename, FILE => $abs_basename, IMPORTS => {}); } my @commands; if ($^O eq 'MSWin32' && $cc =~ /^cl/) { push @commands, qq{$cc $ccflags $cccdlflags $optimize /I "$incdir" /c $source_name /Fo$object_file}; push @commands, qq{$ld $object_file $lddlflags $libperl $perllibs /out:$loadable_object /def:$abs_basename.def /pdb:$abs_basename.pdb}; } elsif ($^O eq 'VMS') { # Mksymlists is only the beginning of the story. open my $opt_fh, '>>', "$abs_basename.opt" or do { carp "Couldn't append to '$abs_basename.opt'"; return }; print $opt_fh "PerlShr/Share\n"; close $opt_fh; my $incdirs = $ccflags =~ s{ /inc[^=]+ (?:=)+ (?:\()? ( [^\/\)]* ) }{}xi ? "$1,$incdir" : $incdir; push @commands, qq{$cc $ccflags $optimize /include=($incdirs) $cccdlflags $source_name /obj=$object_file}; push @commands, qq{$ld $ldflags $lddlflags=$loadable_object $object_file,$abs_basename.opt/OPTIONS,${incdir}perlshr_attr.opt/OPTIONS' $perllibs}; } else { my @extra; if ($^O eq 'MSWin32') { push @extra, "$abs_basename.def"; push @extra, '-l' . ($libperl =~ /lib([^.]+)\./)[0]; } elsif ($^O eq 'cygwin') { push @extra, catfile($incdir, $config->get('useshrplib') ? 'libperl.dll.a' : 'libperl.a'); } elsif ($^O eq 'aix') { $lddlflags =~ s/\Q$(BASEEXT)\E/$abs_basename/; $lddlflags =~ s/\Q$(PERL_INC)\E/$incdir/; } push @commands, qq{$cc $ccflags $optimize "-I$incdir" $cccdlflags -c $source_name -o $object_file}; push @commands, qq{$cc $optimize $object_file -o $loadable_object $lddlflags @extra $perllibs}; } for my $command (@commands) { print "$command\n" if not $args{quiet}; system $command and do { carp "Couldn't execute $command: $!"; return }; } # Skip loading when cross-compiling return 1 if exists $args{skip_load} ? $args{skip_load} : $config->get('usecrosscompile'); require DynaLoader; local @DynaLoader::dl_require_symbols = "boot_$basename"; my $handle = DynaLoader::dl_load_file($loadable_object, 0); if ($handle) { my $symbol = DynaLoader::dl_find_symbol($handle, "boot_$basename") or do { carp "Couldn't find boot symbol for $basename"; return }; my $compilet = DynaLoader::dl_install_xsub('__ANON__::__ANON__', $symbol, $source_name); my $ret = eval { $compilet->(); $package->exported } or carp $@; delete $ExtUtils::HasCompiler::{"$shortname\::"}; eval { DynaLoader::dl_unload_file($handle) } or carp $@; return defined $ret && $ret == 42; } else { carp "Couldn't load $loadable_object: " . DynaLoader::dl_error(); return; } } sub ExtUtils::HasCompiler::Config::get { my (undef, $key) = @_; return $ENV{uc $key} || $Config{$key}; } 1; # ABSTRACT: Check for the presence of a compiler __END__ =pod =encoding UTF-8 =head1 NAME ExtUtils::HasCompiler - Check for the presence of a compiler =head1 VERSION version 0.012 =head1 DESCRIPTION This module tries to check if the current system is capable of compiling, linking and loading an XS module. B: this is an early release, interface stability isn't guaranteed yet. =head1 FUNCTIONS =head2 can_compile_loadable_object(%opts) This checks if the system can compile, link and load a perl loadable object. It may take the following options: =over 4 =item * quiet Do not output the executed compilation commands. =item * config An L (compatible) object for configuration. =item * skip_load This causes can_compile_loadable_object to not try to load the generated object. This defaults to true on a cross-compiling perl. =back =head1 AUTHOR Leon Timmermans =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by Leon Timmermans. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut