File Coverage

blib/lib/Pod/Abstract/Filter/sort.pm
Criterion Covered Total %
statement 12 29 41.3
branch 0 6 0.0
condition n/a
subroutine 4 5 80.0
pod 1 1 100.0
total 17 41 41.4


line stmt bran cond sub pod time code
1             package Pod::Abstract::Filter::sort;
2 1     1   1265 use strict;
  1         3  
  1         62  
3 1     1   7 use warnings;
  1         2  
  1         60  
4              
5 1     1   8 use Data::Dumper;
  1         2  
  1         69  
6              
7 1     1   7 use base qw(Pod::Abstract::Filter);
  1         2  
  1         458  
8              
9             =head1 NAME
10              
11             Pod::Abstract::Filter::sort - alphabetically sort sub-sections within a
12             POD section.
13              
14             =head1 USAGE
15              
16             =over
17              
18             =item *
19              
20             Sort the METHODS section in the target document:
21              
22             paf sort -heading=METHODS Your::Module::Name
23              
24             =item *
25              
26             Sort as specified, where your document has:
27              
28             =head1 METHODS
29              
30             =for sorting
31              
32             {etc}
33              
34             In this case the "=for sorting" label will cause all subheadings to be
35             sorted alphabetically, you don't need to specify a section.
36              
37             paf sort Your::Module::Name
38              
39             =cut
40              
41             our $VERSION = '0.26';
42              
43             sub filter {
44 0     0 1   my $self = shift;
45 0           my $pa = shift;
46            
47 0           my $heading = $self->param('heading');
48 0 0         $heading = 'METHODS' unless defined $heading;
49            
50 0           my @targets = $pa->select("//[\@heading =~ {$heading}]");
51 0           my @spec_targets = $pa->select("//[/for =~ {^sorting}]");
52            
53 0 0         if($self->param('heading')) {
54 0           push @targets, @spec_targets;
55             } else {
56 0 0         @targets = @spec_targets if @spec_targets;
57             }
58            
59 0           foreach my $t (@targets) {
60 0           my @ignore = $t->select("/[!\@heading]");
61 0           my @to_sort = $t->select("/[\@heading]");
62            
63 0           $t->clear;
64 0           $t->nest(@ignore);
65             $t->nest(
66             sort {
67 0           $a->param('heading')->pod cmp
  0            
68             $b->param('heading')->pod
69             } @to_sort
70             );
71             }
72 0           return $pa;
73             }
74              
75             =head1 AUTHOR
76              
77             Ben Lilburne
78              
79             =head1 COPYRIGHT AND LICENSE
80              
81             Copyright (C) 2009-2025 Ben Lilburne
82              
83             This program is free software; you can redistribute it and/or modify
84             it under the same terms as Perl itself.
85              
86             =cut
87              
88             1;