| 1 | package Perl::Critic::Policy::Bangs::ProhibitDebuggingModules; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | our $VERSION = '1.14'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use List::MoreUtils qw(any); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Perl::Critic::Utils qw( :severities ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use base qw(Perl::Critic::Policy); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | Perl::Critic::Policy::Bangs::ProhibitDebuggingModules - Prohibit loading of debugging modules like Data::Dumper | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | This policy prohibits loading common debugging modules like L<Data::Dumper>. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | While such modules are incredibly useful during development and debugging, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | they should probably not be loaded in production use. If this policy is | ||||||||||||||||||||||||||||||||||||||||||
| 22 | violated, it probably means you forgot to remove a C<use Data::Dumper;> line | ||||||||||||||||||||||||||||||||||||||||||
| 23 | that you had added when you were debugging. | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | The current list of detected debugging modules is: | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | =item * L<Data::Dumper> | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | =item * L<Data::Printer> | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | To add more modules that shouldn't be loaded unless you're actively debugging | ||||||||||||||||||||||||||||||||||||||||||
| 38 | something, add them in F<.perlcriticrc> using the C<debugging_modules> option. | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | Readonly::Scalar my $DESC => q/Debugging module loaded/; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | name => 'debugging_modules', | |||||||||||||||||||||||||||||||||||||||||
| 48 | description => 'Module names which are considered to be banned debugging modules', | ||||||||||||||||||||||||||||||||||||||||||
| 49 | behavior => 'string list', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | list_always_present_values => [qw( | ||||||||||||||||||||||||||||||||||||||||||
| 51 | B::Stats | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | Carp::Always.* | ||||||||||||||||||||||||||||||||||||||||||
| 54 | Carp::Diagnostics | ||||||||||||||||||||||||||||||||||||||||||
| 55 | Carp::REPL | ||||||||||||||||||||||||||||||||||||||||||
| 56 | Carp::Source::Always | ||||||||||||||||||||||||||||||||||||||||||
| 57 | Carp::Trace | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | Data::Dump | ||||||||||||||||||||||||||||||||||||||||||
| 60 | Data::Dump::Filtered | ||||||||||||||||||||||||||||||||||||||||||
| 61 | Data::Dump::Streamer | ||||||||||||||||||||||||||||||||||||||||||
| 62 | Data::Dump::Trace | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | Data::Dumper.* | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | Data::Printer | ||||||||||||||||||||||||||||||||||||||||||
| 67 | Data::PrettyPrintObjects | ||||||||||||||||||||||||||||||||||||||||||
| 68 | Data::Show | ||||||||||||||||||||||||||||||||||||||||||
| 69 | Data::Skeleton | ||||||||||||||||||||||||||||||||||||||||||
| 70 | Data::TreeDumper | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | DDP | ||||||||||||||||||||||||||||||||||||||||||
| 73 | DDS | ||||||||||||||||||||||||||||||||||||||||||
| 74 | Devel::Ditto | ||||||||||||||||||||||||||||||||||||||||||
| 75 | Devel::Dwarn | ||||||||||||||||||||||||||||||||||||||||||
| 76 | Devel::Modlist | ||||||||||||||||||||||||||||||||||||||||||
| 77 | Devel::Monitor | ||||||||||||||||||||||||||||||||||||||||||
| 78 | Devel::StackTrace | ||||||||||||||||||||||||||||||||||||||||||
| 79 | Devel::Trace | ||||||||||||||||||||||||||||||||||||||||||
| 80 | Devel::Unplug | ||||||||||||||||||||||||||||||||||||||||||
| 81 | ) ], # DDP and DDS are shorthand module names | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 9 | ▶ | sub default_severity { return $SEVERITY_HIGH } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub default_themes { return qw/ bangs maintenance / } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 5 | ▶ | sub applies_to { return 'PPI::Statement::Include' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 21 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 21 | my ($self, $include, undef) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 21 | ▶ | return unless defined $include->type and ($include->type eq 'use' || $include->type eq 'require'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $include->type and $include->type eq "use" || $include->type eq "require"
$include->type eq "use" or $include->type eq "require"
MC/DC0%0/3
defined $include->type and $include->type eq "use" || $include->type eq "require"
defined $include->type
$include->type eq "use"
$include->type eq "require"
Truth table50%2/4
A and B or C
A= defined $include->typeB= $include->type eq "use"C= $include->type eq "require"
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 21 | ▶ | my $included = $include->module or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 16 | my $EXPL = "You've loaded $included, which probably shouldn't be loaded in production"; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 16 | my @banned = ( keys %{ $self->{_debugging_modules} } ); | |||||||||||||||||||||||||||||||||||||||||
| 96 | return $self->violation($DESC, $EXPL, $include) | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 16 | ▶ | if (any { $included =~ m/$_/xms } @banned); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | =head1 AFFILIATION | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | This policy is part of L<Perl::Critic::Bangs>. | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | Mike Doherty C<doherty@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | Copyright (c) 2012 Mike Doherty | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 114 | it under the terms of the Artistic License 2.0. | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||