The Role of Critique

$self->_select("SELECT * FROM foo WHERE foo_id",123)

dbh

package SuperProject::Role::WithSelect; use Moo::Role; requires 'dbh'; sub _select { my $self = shift; my $sql = shift; my @binds = @_; return $self->dbh->selectall_arrayref( $sql, { Slice => {} }, @binds); } 1;

bash$ perlcritic --verbose 10 SuperProject/Role/WithSelect.pm Private subroutine/method '_select' declared but not used at line 7, column 1. Subroutines::ProhibitUnusedPrivateSubroutines (Severity: 3) By convention Perl authors (like authors in many other languages) indicate private methods and variables by inserting a leading underscore before the identifier. This policy catches such subroutines which are not used in the file which declares them. This module defines a 'use' of a subroutine as a subroutine or method call to it (other than from inside the subroutine itself), a reference to it (i.e. `my $foo = \&_foo'), a `goto' to it outside the subroutine itself (i.e. `goto &_foo'), or the use of the subroutine's name as an even-numbered argument to `use overload'.

_select

select

select

## no critic

## no critic

Subroutines::ProhibitUnusedPrivateSubroutines

Subroutines::ProhibitUnusedPrivateSubroutines

perlcriticrc

Moo::Role

[Subroutines::ProhibitUnusedPrivateSubroutines] skip_when_using = Moo::Role

Over the last week I've been noodling with a minor improvement to Perl Critic to do withand roles. Sometimes I write roles that are essentially importers for utility methods - methods that are essentially imported into the class but don't become part of the public interface. Here's an example of such a role, something that allows you to writeon any class that has aattribute.So what's the problem (aside from the fact that I should have been using DBIx::Class for the databse stuff?)Ooops. Perl::Critic is complaining about that private subroutine that's not used in the role class. I guess I could change the method name fromto, but I don't wantto become part of the public interface to the class that's consuming this role. Another option would be to use adeclaration. But that's tedious, almost every role I write is going to be littered with extraniousdelcarations and that's often a sign that something is seriously wrong. What we need is some way to turn offfor all our roles, but leave it on for everything else. And that's what I've been working on with help from Jeff Thalhammer over the last week. With the release of Perl::Critic that was released today you can tweakin yourto automatically turn itself off for a file if somewhere in that file you use a particular module, like, say,