andreas1234567 has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

I would like Perl::Critic to behave differently depending on file type (i.e. file extension). I use emacs' cperl-mode with perlcritic-mode on test files (.t) as well as on perl modules (.pm) and perl scripts (.pl).

For example I don't want to require my test files to be contained in a package, as dictated by Perl::Critic::Policy::Modules::RequireExplicitPackage. This policy allows exceptions for perl scripts as defined by sub is_script in Perl::Critic::Utils, but there is no equivalent for test files.

I can, of course, add #! to the beginning of all test files, but I would rather solve the problem than go around it. I am thinking about a patch that adds sub is_test_script to Perl::Critic::Utils[1] and adds a parameter exempt_test_scripts to the policy.

Any guidance on the narrow path to enlightenment is appreciated.

[1] Yes, even though the source says This module is way too large.

--
No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]

Replies are listed 'Best First'.
Re: Perl::Critic and file types
by rir (Vicar) on Mar 02, 2009 at 15:21 UTC
    If I felt as you do, I'd probably add a perlcritic check to my makes. But you could just use themes something like this:
    #!/usr/bin/perl use warnings; use strict; use File::Basename; my ( $DEFAULT, $PM_THEME, $PL_THEME, $T_THEME ) = qw( rir rir_large rir rir ); my %themes = ( '.t' => $T_THEME, '.pm' => $PM_THEME, '.pl' => $PL_THEME, ); my $file = pop @ARGV; my ( $name, $path, $suffix ) = fileparse( $file, qr{\.\w+} ); local $, = ' '; # forking could scale up better if ($suffix) { print `perlcritic @ARGV -theme $themes{$suffix} $file`; } else { # STDIN or unknown extension ( or anything else YYY? ) print `perlcritic @ARGV -theme $DEFAULT $file`; }
    Be well,
    rir
Re: Perl::Critic and file types
by elliot (Novice) on Mar 03, 2009 at 12:35 UTC