This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update bignum, Math::BigInt, Math::BigInt::FastCalc, and Math::BigRat
[perl5.git] / Porting / manifest_lib.pl
1 #!/usr/bin/perl
2
3 use strict;
4
5 =head1 NAME
6
7 Porting/manifest_lib.pl - functions for managing manifests
8
9 =head1 SYNOPSIS
10
11     require './Porting/manifest_lib.pl';
12
13 =head1 DESCRIPTION
14
15 This file makes available one function, C<sort_manifest()>.
16
17 =head2 C<sort_manifest>
18
19 Treats its arguments as (chomped) lines from a MANIFEST file, and returns that
20 listed sorted appropriately.
21
22 =cut
23
24 # Try to get a sane sort. case insensitive, more or less
25 # sorted such that path components are compared independently,
26 # and so that lib/Foo/Bar sorts before lib/Foo-Alpha/Baz
27 # and so that lib/Foo/Bar.pm sorts before lib/Foo/Bar/Alpha.pm
28 # and so that configure and Configure sort together.
29 sub sort_manifest {
30     return
31     # case insensitive sorting of directory components independently.
32     map { $_->[0] } # extract the full line
33     sort {
34         $a->[1] cmp $b->[1] || # sort in order of munged filename
35         $a->[0] cmp $b->[0]    # then by the exact text in full line
36     }
37     map {
38         # split out the filename and the description
39         my ($f) = split /\s+/, $_, 2;
40         # lc the filename so Configure and configure sort together in the list
41         my $m= lc $f; # $m for munged
42         # replace slashes by nulls, this makes short directory names sort before
43         # longer ones, such as "foo/" sorting before "foo-bar/"
44         $m =~ s!/!\0!g;
45         # replace the extension (only one) by null null extension.
46         # this puts any foo/blah.ext before any files in foo/blah/
47         $m =~ s{(?<!\A)(\.[^.]+\z)}{\0\0$1};
48
49         # return the original string, and the munged filename
50         [ $_, $m ];
51     } @_;
52 }
53
54 1;
55
56 # ex: set ts=8 sts=4 sw=4 et: