@@ -1,5 +1,13 @@
Revision history for Perl-Critic-Bangs
+1.10 Mon Aug 20 14:26:07 CDT 2012
+====================================
+[ENHANCEMENTS]
+Added ProhibitDebuggingModules. Thanks to Mike Doherty for the code,
+and to Breno G. de Oliveira, Joel Berger and Jeffrey Thalhammer for
+helping with implementation details.
+
+
1.08 Mon Jun 20 11:56:49 CDT 2011
====================================
Official release, no changes from 1.07_02
@@ -7,6 +7,7 @@ lib/Perl/Critic/Policy/Bangs/ProhibitNumberedNames.pm
lib/Perl/Critic/Policy/Bangs/ProhibitRefProtoOrProto.pm
lib/Perl/Critic/Policy/Bangs/ProhibitUselessRegexModifiers.pm
lib/Perl/Critic/Policy/Bangs/ProhibitVagueNames.pm
+lib/Perl/Critic/Policy/Bangs/ProhibitDebuggingModules.pm
Changes
Makefile.PL
@@ -28,6 +29,7 @@ t/99_pod_coverage.t
t/Bangs/ProhibitBitwiseOperators.run
t/Bangs/ProhibitCommentedOutCode.run
+t/Bangs/ProhibitDebuggingModules.run
t/Bangs/ProhibitFlagComments.run
t/Bangs/ProhibitNoPlan.run
t/Bangs/ProhibitNumberedNames.run
@@ -39,3 +41,4 @@ t/tlib/Perl/Critic/TestUtilitiesWithMinimalDependencies.pm
t/tlib/ViolationTest.pm
t/tlib/ViolationTest2.pm
META.yml Module meta-data (added by MakeMaker)
+META.json Module JSON meta-data (added by MakeMaker)
@@ -0,0 +1,61 @@
+{
+ "abstract" : "Perl::Critic::Bangs - A collection of policies for Perl::Critic",
+ "author" : [
+ "Andy Lester <andy@petdance.com>"
+ ],
+ "dynamic_config" : 1,
+ "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112621",
+ "license" : [
+ "perl_5"
+ ],
+ "meta-spec" : {
+ "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
+ "version" : "2"
+ },
+ "name" : "Perl-Critic-Bangs",
+ "no_index" : {
+ "directory" : [
+ "t",
+ "inc"
+ ]
+ },
+ "prereqs" : {
+ "build" : {
+ "requires" : {
+ "ExtUtils::MakeMaker" : 0
+ }
+ },
+ "configure" : {
+ "requires" : {
+ "ExtUtils::MakeMaker" : 0
+ }
+ },
+ "runtime" : {
+ "requires" : {
+ "PPI::Cache" : 0,
+ "PPI::Document" : 0,
+ "Perl::Critic" : "1.098",
+ "Perl::Critic::Policy" : 0,
+ "Perl::Critic::PolicyFactory" : 0,
+ "Perl::Critic::PolicyParameter" : 0,
+ "Perl::Critic::TestUtils" : 0,
+ "Perl::Critic::UserProfile" : 0,
+ "Perl::Critic::Utils" : 0,
+ "Perl::Critic::Violation" : 0,
+ "Readonly" : 0,
+ "Test::More" : "0.96",
+ "Test::Perl::Critic" : "1.01"
+ }
+ }
+ },
+ "release_status" : "stable",
+ "resources" : {
+ "license" : [
+ "http://dev.perl.org/licenses/"
+ ],
+ "repository" : {
+ "url" : "git://github.com/petdance/perl-critic-bangs.git"
+ }
+ },
+ "version" : "1.10"
+}
@@ -1,37 +1,37 @@
---- #YAML:1.0
-name: Perl-Critic-Bangs
-version: 1.08
-abstract: Perl::Critic::Bangs - A collection of policies for Perl::Critic
+---
+abstract: 'Perl::Critic::Bangs - A collection of policies for Perl::Critic'
author:
- - Andy Lester <andy@petdance.com>
-license: perl
-distribution_type: module
-configure_requires:
- ExtUtils::MakeMaker: 0
+ - 'Andy Lester <andy@petdance.com>'
build_requires:
- ExtUtils::MakeMaker: 0
+ ExtUtils::MakeMaker: 0
+configure_requires:
+ ExtUtils::MakeMaker: 0
+dynamic_config: 1
+generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112621'
+license: perl
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
+name: Perl-Critic-Bangs
+no_index:
+ directory:
+ - t
+ - inc
requires:
- Perl::Critic: 1.098
- Perl::Critic::Policy: 0
- Perl::Critic::PolicyFactory: 0
- Perl::Critic::PolicyParameter: 0
- Perl::Critic::TestUtils: 0
- Perl::Critic::UserProfile: 0
- Perl::Critic::Utils: 0
- Perl::Critic::Violation: 0
- PPI::Cache: 0
- PPI::Document: 0
- Readonly: 0
- Test::More: 0
- Test::Perl::Critic: 1.01
+ PPI::Cache: 0
+ PPI::Document: 0
+ Perl::Critic: 1.098
+ Perl::Critic::Policy: 0
+ Perl::Critic::PolicyFactory: 0
+ Perl::Critic::PolicyParameter: 0
+ Perl::Critic::TestUtils: 0
+ Perl::Critic::UserProfile: 0
+ Perl::Critic::Utils: 0
+ Perl::Critic::Violation: 0
+ Readonly: 0
+ Test::More: 0.96
+ Test::Perl::Critic: 1.01
resources:
- license: http://dev.perl.org/licenses/
- repository: git://github.com/petdance/perl-critic-bangs.git
-no_index:
- directory:
- - t
- - inc
-generated_by: ExtUtils::MakeMaker version 6.56
-meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.4.html
- version: 1.4
+ license: http://dev.perl.org/licenses/
+ repository: git://github.com/petdance/perl-critic-bangs.git
+version: 1.10
@@ -22,7 +22,7 @@ my %parms = (
'PPI::Cache' => 0,
'PPI::Document' => 0,
'Readonly' => 0,
- 'Test::More' => 0,
+ 'Test::More' => '0.96', # For subtest()
'Test::Perl::Critic' => 1.01,
},
LICENSE => 'perl',
@@ -11,11 +11,11 @@ Perl::Critic::Bangs - A collection of handy Perl::Critic policies
=head1 VERSION
-Version 1.08
+Version 1.10
=cut
-our $VERSION = '1.08';
+our $VERSION = '1.10';
=head1 SYNOPSIS
@@ -8,7 +8,7 @@ use Readonly;
use Perl::Critic::Utils qw{ :severities :classification :data_conversion };
use base 'Perl::Critic::Policy';
-our $VERSION = '1.08';
+our $VERSION = '1.10';
#-----------------------------------------------------------------------------
@@ -5,7 +5,7 @@ use warnings;
use Perl::Critic::Utils;
use base 'Perl::Critic::Policy';
-our $VERSION = '1.08';
+our $VERSION = '1.10';
#---------------------------------------------------------------------------
@@ -0,0 +1,108 @@
+package Perl::Critic::Policy::Bangs::ProhibitDebuggingModules;
+use strict;
+use warnings;
+
+our $VERSION = '1.10';
+
+use List::MoreUtils qw(any);
+use Readonly;
+use Perl::Critic::Utils qw( :severities );
+use base qw(Perl::Critic::Policy);
+
+=head1 NAME
+
+Perl::Critic::Policy::Bangs::ProhibitDebuggingModules - Prohibit loading of debugging modules like Data::Dumper
+
+=head1 DESCRIPTION
+
+This policy prohibits loading common debugging modules like L<Data::Dumper>.
+
+While such modules are incredibly useful during development and debugging,
+they should probably not be loaded in production use. If this policy is
+violated, it probably means you forgot to remove a C<use Data::Dumper;> line
+that you had added when you were debugging.
+
+=head1 CONFIGURATION
+
+The current list of detected debugging modules is:
+
+=over 4
+
+=item * L<Data::Dumper>
+
+=item * L<Data::Printer>
+
+=back
+
+To add more modules that shouldn't be loaded unless you're actively debugging
+something, add them in F<.perlcriticrc> using the C<deubgging_modules> option.
+
+=cut
+
+Readonly::Scalar my $DESC => q/Debugging module loaded/;
+
+sub supported_parameters {
+ return (
+ {
+ name => 'debugging_modules',
+ description => 'Module names which are considered to be banned debugging modules',
+ behavior => 'string list',
+ list_always_present_values => [qw(
+ Data::Dump
+ Data::Dump::Filtered
+ Data::Dump::Streamer
+ Data::Dump::Trace
+
+ Data::Dumper
+ Data::Dumper::Concise
+ Data::Dumper::Concise::Sugar
+ Data::Dumper::EasyOO
+ Data::Dumper::Names
+ Data::Dumper::Simple
+
+ Data::Printer
+ Data::PrettyPrintObjects
+ Data::Skeleton
+ Data::TreeDumper
+
+ DDP
+ DDS
+ Devel::Dwarn
+ ) ], # DDP and DDS are shorthand module names
+ }
+ );
+}
+sub default_severity { return $SEVERITY_HIGH }
+sub default_themes { return qw/ bangs maintenance / }
+sub applies_to { return 'PPI::Statement::Include' }
+
+sub violates {
+ my ($self, $include, undef) = @_;
+ return unless defined $include->type and ($include->type eq 'use' || $include->type eq 'require');
+ my $included = $include->module or return;
+ my $EXPL = "You've loaded $included, which probably shouln't be loaded in production";
+
+ my @banned = ( keys %{ $self->{_debugging_modules} } );
+ return $self->violation($DESC, $EXPL, $include)
+ if any { $included eq $_ } @banned;
+ return;
+}
+
+=head1 AFFILIATION
+
+This policy is part of L<Perl::Critic::Bangs>.
+
+=head1 AUTHOR
+
+Mike Doherty C<doherty@cpan.org>
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright (c) 2012 Mike Doherty
+
+This library is free software; you can redistribute it and/or modify
+it under the terms of the Artistic License 2.0.
+
+=cut
+
+1;
@@ -5,7 +5,7 @@ use warnings;
use Perl::Critic::Utils;
use base 'Perl::Critic::Policy';
-our $VERSION = '1.08';
+our $VERSION = '1.10';
#----------------------------------------------------------------------------
@@ -5,7 +5,7 @@ use warnings;
use Perl::Critic::Utils;
use base 'Perl::Critic::Policy';
-our $VERSION = '1.08';
+our $VERSION = '1.10';
sub supported_parameters { return () }
sub default_severity { return $SEVERITY_LOW }
@@ -5,7 +5,7 @@ use warnings;
use Perl::Critic::Utils;
use base 'Perl::Critic::Policy';
-our $VERSION = '1.08';
+our $VERSION = '1.10';
sub supported_parameters {
return (
@@ -5,7 +5,7 @@ use warnings;
use Perl::Critic::Utils;
use base 'Perl::Critic::Policy';
-our $VERSION = '1.08';
+our $VERSION = '1.10';
sub supported_parameters { return () }
sub default_severity { return $SEVERITY_HIGH }
@@ -7,7 +7,7 @@ use Readonly;
use Perl::Critic::Utils qw{ :severities :classification :ppi };
use base 'Perl::Critic::Policy';
-our $VERSION = '1.08';
+our $VERSION = '1.10';
Readonly::Scalar my $DESC => q{Prohibits adding "m" modifier to compiled regular expressions where it does nothing};
Readonly::Scalar my $EXPL => <<'EOF';
@@ -5,7 +5,7 @@ use warnings;
use Perl::Critic::Utils qw( :booleans :severities );
use base 'Perl::Critic::Policy';
-our $VERSION = '1.08';
+our $VERSION = '1.10';
#----------------------------------------------------------------------------
@@ -12,6 +12,8 @@ allow_leading_tabs = 0
[-Documentation::RequirePodLinksIncludeText]
[-Documentation::RequirePodSections]
+[-ErrorHandling::RequireCarping]
+
[-Miscellanea::RequireRcsKeywords]
[-Modules::RequireVersionVar]
@@ -9,7 +9,7 @@ use English qw(-no_match_vars);
#-----------------------------------------------------------------------------
-our $VERSION = '1.08';
+our $VERSION = '1.10';
#-----------------------------------------------------------------------------
@@ -17,7 +17,7 @@ Perl::Critic::TestUtils::block_perlcriticrc();
my @bundled_policy_names = bundled_policy_names();
-plan tests => ( 14 * scalar @bundled_policy_names );
+plan tests => scalar @bundled_policy_names;
# pre-compute for version comparisons
my $version_string = __PACKAGE__->VERSION;
@@ -25,8 +25,9 @@ my $version_string = __PACKAGE__->VERSION;
#-----------------------------------------------------------------------------
# Test module interface for each Policy subclass
-{
- for my $mod ( @bundled_policy_names ) {
+for my $mod ( @bundled_policy_names ) {
+ subtest $mod => sub {
+ plan tests => 14;
use_ok($mod);
can_ok($mod, 'applies_to');
@@ -11,7 +11,7 @@ use Perl::Critic::PolicyParameter qw{ $NO_DESCRIPTION_AVAILABLE };
use Perl::Critic::Utils qw( policy_short_name );
use Perl::Critic::TestUtils qw(bundled_policy_names);
-use Test::More tests => 12;
+use Test::More tests => 14;
Perl::Critic::TestUtils::block_perlcriticrc();
@@ -24,7 +24,7 @@ if (@ARGV) {
my @policies = keys %{$subtests}; # get a list of all tests
# This is inefficient, but who cares...
for (@ARGV) {
- next if m/::/xms;
+ next if m/::/;
if (!s{\A t[\\/](\w+)[\\/](\w+)\.run \z}{$1\::$2}xms) {
die 'Unknown argument ' . $_;
}
@@ -97,7 +97,7 @@ for my $policy ( sort keys %{$subtests} ) {
# If any optional modules are NOT installed, then there should be no failures.
if ($subtest->{optional_modules}) {
MODULE:
- for my $module (split m/,\s*/xms, $subtest->{optional_modules}) {
+ for my $module (split m/,\s*/, $subtest->{optional_modules}) {
eval "require $module"; ## no critic (ProhibitStringyEval)
if ($EVAL_ERROR) {
$expected_failures = 0;
@@ -17,7 +17,7 @@ if (! defined $last_version) {
}
sub check_version {
- return if (! m{blib/script/}xms && ! m{\.pm \z}xms);
+ return if (! m{blib/script/} && ! m{\.pm\z});
local $/ = undef;
my $fh;
@@ -29,7 +29,7 @@ sub check_version {
$content =~ s/^__END__.*//xms;
# only look at perl scripts, not sh scripts
- return if (m{blib/script/}xms && $content !~ m/\A \#![^\r\n]+?perl/xms);
+ return if (m{blib/script/} && $content !~ m/\A \#![^\r\n]+?perl/xms);
my @version_lines = $content =~ m/ ( [^\n]* \$VERSION [^\n]* ) /gxms;
# Special cases for printing/documenting version numbers
@@ -32,7 +32,7 @@ my %implied = (
my @pm;
find(
{
- wanted => sub { push @pm, $_ if m/\.pm \z/xms && !m/svn/xms },
+ wanted => sub { push @pm, $_ if m/\.pm\z/ && !m/svn/ },
no_chdir => 1,
},
'lib'
@@ -50,9 +50,9 @@ for my $file (@pm) {
for my $pkg (@pkgs) {
my $name = "$pkg";
- next if $name !~ m/::/xms;
- next if $name =~ m/::_private::/xms;
- next if $name =~ m/List::Util::[a-z]+/xms;
+ next if $name !~ m/::/;
+ next if $name =~ m/::_private::/;
+ next if $name =~ m/List::Util::[a-z]+/;
# subroutine declaration with absolute name?
# (bad form, but legal)
@@ -0,0 +1,37 @@
+## name Basic configuration - passes
+## failures 0
+## cut
+
+use Test::More;
+use strict;
+require warnings;
+use 5.8.8;
+require 5.8.8;
+
+## name Basic configuration - fail
+## failures 2
+## cut
+
+require Data::Dumper;
+use Data::Dumper 1;
+
+
+#### Once more with <s>feeling</s> configuration!
+## name With configuration - passes
+## failures 0
+## parms { debugging_modules => 'strict' }
+## cut
+
+use Test::More;
+require warnings;
+use 5.8.8;
+require 5.8.8;
+
+## name With configuration - fail
+## failures 3
+## parms { debugging_modules => 'strict' }
+## cut
+
+use strict;
+require Data::Dumper;
+use Data::Dumper 1;