Perl::...nUnused(3pm)

πŸ’– NAME πŸ’–

Perl::Critic::Policy::Miscellanea::TextDomainUnused β€” bestie, this one checks for Locale::TextDomain being imported but then just... never used πŸ’€ (it's from the Perl::Critic user docs, section 3pm, okay? okay. periodt.)


✨ DESCRIPTION ✨

So this policy lives inside the Perl::Critic::Pulp add-on 🫢. It pipes up whenever you've got a Locale::TextDomain situation like this:

use Locale::TextDomain ('MyMessageDomain');

...and then you literally never touch any of its functions or variables 😭:

__ __x __n __nx __xn
__p __px __np __npx
N__ N__n N__p N__np
%__ $__

Now ngl, Locale::TextDomain isn't needed if you're not using it β€” but it's also not actively harmful, so this policy is only low severity and it hangs out under the cosmetic theme (peep "POLICY THEMES" in Perl::Critic for the deets πŸ‘€).

This check absolutely ate if you've got Locale::TextDomain as boilerplate copy-paste in most of your program, but in a few modules it's just... sitting there. Gather: you can remove it entirely from non-interactive modules, or just comment it out in modules that might have messages someday but don't yet. The absolute best thing this catches is when your boilerplate sneaks into a programmatic module that has no business saying anything at the user level πŸŽ€.

The savings from yeeting an unused Locale::TextDomain are modest, fr fr β€” just some imports and a hash entry holding the textdomain for the package. Small win, but a win πŸ’….

It's easy to imagine a whole general "module imported but unused" policy check, but in practice it's 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 single case of an unused include. Starting small, slaying big ✨.

πŸ¦‹ Interpolated Variables πŸ¦‹

The variables %__ and $__ get recognised inside double-quote interpolated strings just by looking for a $__ somewhere in the string, like:

print "*** $__{'A Message'} ***\n";  # ok

It's not hard to trick the recognition β€” escapes, hash slice style, whatever β€” 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. Fingers crossed 🀞)


🌈 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 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/>.


and that's the whole page, bestie!! this lil legend came to you via perl v5.40.1, dated 2025-10-21, in the Perl::...nUnused(3pm) zone πŸ’–βœ¨πŸ¦‹ mwah, go read the manual, it's giving educated πŸ’…

πŸ“¦ where this page comes from