Perl::Critic::Policy::Miscellanea::TextDomainUnused3pm
Check for locale::textdomain imported but unused
Overview
This policy is part of the "Perl::Critic::Pulp" add-on. It reports when you have "Locale::TextDomain" like
use Locale::TextDomain ('MyMessageDomain');
but then don't use any of its functions or variables
__ __x __n __nx __xn__p __px __np __npxN__ N__n N__p N__np%__ $__
"Locale::TextDomain" is not needed when not used, but it's also not actively harmful so this policy is only low severity 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 unused. You can 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 holding the "textdomain" for the package.
It's easy to imagine a general kind of "module imported but unused" policy check, 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 policy 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.)
Home page
<http://user42.tuxfamily.org/perl-critic-pulp/index.html>
Releases
4 releases since Debian 10 (Buster); the text changed 1 time.