diff options
author | Aaron Crane <arc@cpan.org> | 2016-10-12 10:34:13 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2016-10-24 17:36:43 +0200 |
commit | 4a59181454f23dbf43f396b924ff7434b63c9d98 (patch) | |
tree | b446470ee4a2e5ac745caca7061675c35385bb16 /Porting/manifest_lib.pl | |
parent | d3148f758506efd28325dfd8e1b698385133f0cd (diff) | |
download | perl-4a59181454f23dbf43f396b924ff7434b63c9d98.tar.gz |
RT#129229: move sort_manifest() into its own library
This means that the MANIFEST.srt target in the Makefile no longer needs
to load a library that depends on Cwd (and other potentially-dynamic
modules). That in turn fixes a missing-dependency bug in the Makefile.
Diffstat (limited to 'Porting/manifest_lib.pl')
-rw-r--r-- | Porting/manifest_lib.pl | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Porting/manifest_lib.pl b/Porting/manifest_lib.pl new file mode 100644 index 0000000000..0b63046056 --- /dev/null +++ b/Porting/manifest_lib.pl @@ -0,0 +1,53 @@ +#!/usr/bin/perl + +use strict; + +=head1 NAME + +Porting/manifest_lib.pl - functions for managing manifests + +=head1 SYNOPSIS + + require './Porting/manifest_lib.pl'; + +=head1 DESCRIPTION + +=head2 C<sort_manifest> + +Treats its arguments as (chomped) lines from a MANIFEST file, and returns that +listed sorted appropriately. + +=cut + +# Try to get a sane sort. case insensitive, more or less +# sorted such that path components are compared independently, +# and so that lib/Foo/Bar sorts before lib/Foo-Alpha/Baz +# and so that lib/Foo/Bar.pm sorts before lib/Foo/Bar/Alpha.pm +# and so that configure and Configure sort together. +sub sort_manifest { + return + # case insensitive sorting of directory components independently. + map { $_->[0] } # extract the full line + sort { + $a->[1] cmp $b->[1] || # sort in order of munged filename + $a->[0] cmp $b->[0] # then by the exact text in full line + } + map { + # split out the filename and the description + my ($f) = split /\s+/, $_, 2; + # lc the filename so Configure and configure sort together in the list + my $m= lc $f; # $m for munged + # replace slashes by nulls, this makes short directory names sort before + # longer ones, such as "foo/" sorting before "foo-bar/" + $m =~ s!/!\0!g; + # replace the extension (only one) by null null extension. + # this puts any foo/blah.ext before any files in foo/blah/ + $m =~ s!(\.[^.]+\z)!\0\0$1!; + # return the original string, and the munged filename + [ $_, $m ]; + } @_; +} + +1; + +# ex: set ts=8 sts=4 sw=4 et: |