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


Perl-Critic-Pulp documentation  | view source Contained in the Perl-Critic-Pulp distribution.

Index


NAME

Top

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

DESCRIPTION

Top

This policy is part of the Perl::Critic::Pulp|Perl::Critic::Pulp addon. It reports when you have Locale::TextDomain|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 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 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

Top

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

HOME PAGE

Top

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

COPYRIGHT

Top


Perl-Critic-Pulp documentation  | view source Contained in the Perl-Critic-Pulp distribution.