Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add perlcritic to the mix #11

Merged
merged 1 commit into from Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion dist.ini
Expand Up @@ -36,8 +36,12 @@ File::Spec = 0.80
remove = strict
remove = warnings
remove = vars
remove = Exporter
remove = constant
remove = utf8
remove = Exporter

; optional test dep
remove = Devel::Hide

[Author::Plicease::Upload]
cpan = 1
Expand Down
14 changes: 9 additions & 5 deletions lib/Class/Inspector.pm
Expand Up @@ -48,7 +48,10 @@ an easier, more friendly interface to this information.
# We can safely ignore any failure here.
BEGIN {
local $@;
eval "require utf8; utf8->import";
eval {
require utf8;
utf8->import;
};
}

# Predefine some regexs
Expand Down Expand Up @@ -458,7 +461,8 @@ sub methods {
while ( my $cl = shift @queue ) {
push @path, $cl;
unshift @queue, grep { ! $seen{$_}++ }
map { s/^::/main::/; s/\'/::/g; $_ }
map { s/^::/main::/; s/\'/::/g; $_ } ## no critic
map { "$_" }
( @{"${cl}::ISA"} );
}

Expand Down Expand Up @@ -552,7 +556,7 @@ sub subclasses {
sub _subnames {
my ($class, $name) = @_;
return sort
grep {
grep { ## no critic
substr($_, -2, 2, '') eq '::'
and
/$RE_IDENTIFIER/o
Expand All @@ -578,7 +582,7 @@ sub children {

# Find all the Foo:: elements in our symbol table
no strict 'refs';
map { "${name}::$_" } sort grep { s/::$// } keys %{"${name}::"};
map { "${name}::$_" } sort grep { s/::$// } keys %{"${name}::"}; ## no critic
}

# As above, but recursively
Expand All @@ -594,7 +598,7 @@ sub recursive_children {
while ( my $namespace = $children[$i++] ) {
push @children, map { "${namespace}::$_" }
grep { ! /^::/ } # Ignore things like ::ISA::CACHE::
grep { s/::$// }
grep { s/::$// } ## no critic
keys %{"${namespace}::"};
}

Expand Down
3 changes: 1 addition & 2 deletions lib/Class/Inspector/Functions.pm
Expand Up @@ -5,13 +5,12 @@ use strict;
use warnings;
use Exporter ();
use Class::Inspector ();
use base qw( Exporter );

# ABSTRACT: Get information about a class and its structure
# VERSION

BEGIN {
our @ISA = 'Exporter';


our @EXPORT = qw(
installed
Expand Down
50 changes: 50 additions & 0 deletions perlcriticrc
@@ -0,0 +1,50 @@
severity = 1
only = 1

[Freenode::ArrayAssignAref]
[Freenode::BarewordFilehandles]
[Freenode::ConditionalDeclarations]
[Freenode::ConditionalImplicitReturn]
[Freenode::DeprecatedFeatures]
[Freenode::DiscouragedModules]
[Freenode::DollarAB]
[Freenode::Each]
[Freenode::EmptyReturn]
[Freenode::IndirectObjectNotation]
[Freenode::LexicalForeachIterator]
[Freenode::LoopOnHash]
[Freenode::ModPerl]
[Freenode::OpenArgs]
[Freenode::OverloadOptions]
[Freenode::POSIXImports]
[Freenode::PackageMatchesFilename]
[Freenode::PreferredAlternatives]
[Freenode::Prototypes]
[Freenode::StrictWarnings]
extra_importers = Test2::V0
[Freenode::Threads]
[Freenode::Wantarray]
[Freenode::WarningsSwitch]
[Freenode::WhileDiamondDefaultAssignment]

[BuiltinFunctions::ProhibitBooleanGrep]
[BuiltinFunctions::ProhibitStringyEval]
[BuiltinFunctions::ProhibitStringySplit]
[BuiltinFunctions::ProhibitVoidGrep]
[BuiltinFunctions::ProhibitVoidMap]
[ClassHierarchies::ProhibitExplicitISA]
[ClassHierarchies::ProhibitOneArgBless]
[CodeLayout::ProhibitHardTabs]
allow_leading_tabs = 0
[CodeLayout::ProhibitTrailingWhitespace]
[CodeLayout::RequireConsistentNewlines]
[ControlStructures::ProhibitLabelsWithSpecialBlockNames]
[ControlStructures::ProhibitMutatingListFunctions]
[ControlStructures::ProhibitUnreachableCode]
[InputOutput::ProhibitBarewordFileHandles]
[InputOutput::ProhibitJoinedReadline]
[InputOutput::ProhibitTwoArgOpen]
[Miscellanea::ProhibitFormats]
[Miscellanea::ProhibitUselessNoCritic]
[Modules::ProhibitConditionalUseStatements]
;[Modules::RequireEndWithOne]
14 changes: 8 additions & 6 deletions t/00_diag.t
Expand Up @@ -30,7 +30,7 @@ pass 'okay';

my $max = 1;
$max = $_ > $max ? $_ : $max for map { length $_ } @modules;
our $format = "%-${max}s %s";
our $format = "%-${max}s %s";

spacer;

Expand All @@ -39,31 +39,33 @@ my @keys = sort grep /(MOJO|PERL|\A(LC|HARNESS)_|\A(SHELL|LANG)\Z)/i, keys %ENV;
if(@keys > 0)
{
diag "$_=$ENV{$_}" for @keys;

if($ENV{PERL5LIB})
{
spacer;
diag "PERL5LIB path";
diag $_ for split $Config{path_sep}, $ENV{PERL5LIB};

}
elsif($ENV{PERLLIB})
{
spacer;
diag "PERLLIB path";
diag $_ for split $Config{path_sep}, $ENV{PERLLIB};
}

spacer;
}

diag sprintf $format, 'perl ', $];

foreach my $module (@modules)
{
if(eval qq{ require $module; 1 })
my $pm = "$module.pm";
$pm =~ s{::}{/}g;
if(eval { require $pm; 1 })
{
my $ver = eval qq{ \$$module\::VERSION };
my $ver = eval { $module->VERSION };
$ver = 'undef' unless defined $ver;
diag sprintf $format, $module, $ver;
}
Expand Down
19 changes: 17 additions & 2 deletions t/class_inspector.t
Expand Up @@ -4,7 +4,7 @@

use strict;
use warnings;
use Test::More tests => 54;
use Test::More tests => 56;
use Class::Inspector ();

# To make maintaining this a little faster,
Expand Down Expand Up @@ -313,10 +313,25 @@ PACKAGES: {
our $VERSION = '0.01';
package My::Bar;
our $VERSION = '0.01';
our @ISA = 'My::Foo';
use base qw( My::Foo );
}
TESTS: {
my $rv = Class::Inspector->subclasses( 'My::Foo' );
is_deeply( $rv, [ 'My::Bar' ],
'->subclasses in the presence of an evil ->isa does not crash' );
}


{
{
package Baz;

our @ISA = qw( ::foo bar'baz ); ## no critic
}

is_deeply \@Baz::ISA, [qw( ::foo bar'baz )];

Class::Inspector->methods('Baz');

is_deeply \@Baz::ISA, [qw( ::foo bar'baz )];
}
2 changes: 1 addition & 1 deletion t/class_inspector__devel_hide.t
Expand Up @@ -3,7 +3,7 @@ use warnings;
use Test::More;
use Class::Inspector;

eval q{ use Devel::Hide };
eval { require Devel::Hide };
plan skip_all => 'test requires Devel::Hide' if $@;
plan tests => 2;

Expand Down
2 changes: 1 addition & 1 deletion t/class_inspector_functions.t
Expand Up @@ -114,5 +114,5 @@ sub MyHook::INC {
open my $fh, '<', __FILE__;
return $fh;
}
return;
return ();
}
14 changes: 14 additions & 0 deletions xt/author/critic.t
@@ -0,0 +1,14 @@
use Test2::Require::Module 'Test2::Tools::PerlCritic';
use Test2::Require::Module 'Perl::Critic';
use Test2::Require::Module 'Perl::Critic::Freenode';
use Test2::V0;
use Perl::Critic;
use Test2::Tools::PerlCritic;

my $critic = Perl::Critic->new(
-profile => 'perlcriticrc',
);

perl_critic_ok ['lib','t'], $critic;

done_testing;