NAME
Perl::Critic::Policy::Miscellanea::TextDomainUnused - check for Locale::TextDomain imported but unused
DESCRIPTION
This policy is part of the Perl::Critic::Pulp addon. It reports when you include Locale::TextDomain
like
use Locale::TextDomain ('MyMessageDomain');
but then don't use one of its functions or variables
__ __n __nx __x __xn
N__ N__n
%__ $__
Locale::TextDomain
is unnecessary in that case, but it's also not actively harmful so this policy is only low priority and under the cosmetic
theme (see "POLICY THEMES" in Perl::Critic).
The check is good if you've got Locale::TextDomain
as boilerplate code in most of your program, but in some modules it's not used. You might want to remove it entirely from non-interactive modules, or comment it out from modules which might have messages but don't yet. The best thing picked up is when your boilerplate has got into a programmatic module which shouldn't say anything at the user level.
The saving from removing unused Locale::TextDomain
is modest, just some imports and a hash entry recording the textdomain for the package. It's easy to imagine a general kind of "module imported but unused", but in practice its hard for perlcritic to know the automatic imports of every module, and quite a few modules have side-effects, so this TextDomainUnused just starts with one case of an unused include.
Interpolated Variables
The variables %__
and $__
are recognised in double-quote interpolated strings just by looking for a $__
somewhere in the string, eg.
print "*** $__{'A Message'} ***\n"; # ok
It's not hard to trick the recognition with escapes, or a hash slice style, but in general taking any $__
to be a TextDomain use is close enough. (Perhaps in the future PPI will do a full parse of interpolated expressions.)
SEE ALSO
Perl::Critic::Pulp, Perl::Critic, Locale::TextDomain, Perl::Critic::Policy::Miscellanea::TextDomainPlaceholders
HOME PAGE
http://www.geocities.com/user42_kevin/perl-critic-pulp/index.html
COPYRIGHT
Copyright 2009 Kevin Ryde
Perl-Critic-Pulp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Perl-Critic-Pulp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Perl-Critic-Pulp. If not, see http://www.gnu.org/licenses.