Scroll to navigation

Perl::Critic::Policy::Miscellanea::TextDomainUnused(3) User Contributed Perl Documentation Perl::Critic::Policy::Miscellanea::TextDomainUnused(3)

NAME

Perl::Critic::Policy::Miscellanea::TextDomainUnused - check for Locale::TextDomain imported but unused

DESCRIPTION

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 __npx
    N__ 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.)

SEE ALSO

Perl::Critic::Pulp, Perl::Critic, Locale::TextDomain, Perl::Critic::Policy::Miscellanea::TextDomainPlaceholders

HOME PAGE

<http://user42.tuxfamily.org/perl-critic-pulp/index.html>

COPYRIGHT

Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 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/>.

2021-03-01 perl v5.40.0