You can modify the perlcritic script with a pre and post filter. The changelog provides the following example
Perl::Tidy::perltidy(
prefilter => sub { $_ = $_[0]; s/^method (.*)/sub $1 \#__METHOD/gm; return $_ },
postfilter => sub { $_ = $_[0]; s/^sub (.*?)\s* \#__METHOD/method $1/gm; return $_ }
);
Perlcritic will now treat method
as a sub
for purposes of formatting. We can do the same with func
. I modified my /usr/local/bin/perlcritic to work with func
as follows:
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
package main;
use Perl::Tidy;
my $arg_string = undef;
# give Macs a chance to provide command line parameters
if ($^O =~ /Mac/) {
$arg_string =
MacPerl::Ask( 'Please enter @ARGV (-h for help)',
defined $ARGV[0] ? "\"$ARGV[0]\"" : "" );
}
Perl::Tidy::perltidy(
argv => $arg_string,
prefilter => sub { $_ = $_[0]; s/\W\Kfunc\((.*)/sub($1 \#__FUNC/gm; return $_ },
postfilter => sub { $_ = $_[0]; s/\W\Ksub\((.*?)\s* \#__FUNC/func($1/gm; return $_ }
);