1

We would like to sort use statements alphabetically in the beginning of our classes automatically via perltidy or maybe other tool if available. We already use Test::PerlTidy to test if the code is formatted before committing.

I found that Perl::Tidy has the options prefilter and postfilter. prefilter looks like the better approach, because I can sort the statements as I wish in any logical for me order, then leave it to perltidy to format it.

  1. Would you recommend sorting use statements? The used classes do not depend on using one before the other.
  2. Would you recommend using these Perl::Tidy features?
  3. Is there a better approach?
Беров
  • 1,383
  • 10
  • 22
  • 5
    Tip: Best to leave pragmas (strict, warnings, utf8, open) where they are, or at least first. These are conventionally all lower-case. – ikegami Sep 02 '19 at 21:29
  • 2
    Personally I don't see the point in sorting `use` statements alphabetically. – melpomene Sep 02 '19 at 22:36
  • If there's so many `use` statements that sorting makes sense then see [Import::Into](https://metacpan.org/pod/Import::Into) – zdim Sep 03 '19 at 06:19
  • 2
    I tend to group the use statement. First core modules, then CPAN modules, finally the modules of the company. – BarneySchmale Sep 03 '19 at 06:32
  • @ikegami, Yes, we are aware of these. We use Mojolicious so this is handled already by `use Mojo::Base...` which of course will stay first. @BarneySchmale, this is more or less our current situation. @zdim, thanks for the hint, but for now I think we do not need it. – Беров Sep 03 '19 at 10:50

0 Answers0