File Coverage

blib/lib/Code/TidyAll/Plugin/SortLines/Naturally.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 22 22 100.0


line stmt bran cond sub pod time code
1 1     1   15610 use strict;
  1         3  
  1         29  
2 1     1   5 use warnings;
  1         2  
  1         45  
3              
4             package Code::TidyAll::Plugin::SortLines::Naturally;
5             $Code::TidyAll::Plugin::SortLines::Naturally::VERSION = '0.000003';
6 1     1   4 use Moo;
  1         1  
  1         10  
7             extends 'Code::TidyAll::Plugin';
8              
9 1     1   1159 use Unicode::Collate::Locale ();
  1         44242  
  1         147  
10              
11             has 'locale' => ( is => 'ro', default => 'en_US' );
12              
13             sub transform_source {
14 1     1 1 8470 my ( $self, $source ) = @_;
15              
16 1         13 my $collator = Unicode::Collate::Locale->new( locale => $self->locale );
17             return
18 1         324088 join( "\n", $collator->sort( grep {/\S/} split( /\n/, $source ) ) )
  8         38  
19             . "\n";
20             }
21              
22             1;
23              
24             =pod
25              
26             =encoding UTF-8
27              
28             =head1 NAME
29              
30             Code::TidyAll::Plugin::SortLines::Naturally - Sort lines of a file using Unicode::Collate::Locale
31              
32             =head1 VERSION
33              
34             version 0.000003
35              
36             =head1 SYNOPSIS
37              
38             # In configuration:
39              
40             [SortLines::Naturally]
41             select = .ispell* **/.gitignore
42              
43             =head1 DESCRIPTION
44              
45             Sorts the lines of a file; whitespace lines are discarded. Useful for files
46             containing one entry per line, such as C<.svnignore>, C<.gitignore>, and
47             C<.ispell*>.
48              
49             =head1 CONFIGURATION
50              
51             =over
52              
53             =item locale
54              
55             The locale to use for collation. Defaults to "en_US".
56              
57             =back
58              
59             =head1 ACKNOWLEDGEMENTS
60              
61             This code was essentially pilfered from L
62              
63             =head1 AUTHOR
64              
65             Olaf Alders
66              
67             =head1 COPYRIGHT AND LICENSE
68              
69             This software is copyright (c) 2014 by Olaf Alders.
70              
71             This is free software; you can redistribute it and/or modify it under
72             the same terms as the Perl 5 programming language system itself.
73              
74             =cut
75              
76             __END__