diff options
author | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2013-10-24 20:32:38 +0200 |
---|---|---|
committer | Andreas Guldstrand <andreas.guldstrand@gmail.com> | 2013-10-24 20:32:38 +0200 |
commit | 0e5a36a35f863e91aad439db094607623a0017ca (patch) | |
tree | 9319201f1dcf702c3f6464122e1758df92e1e3cf | |
parent | 5e381bd247f137a2387ddb243033237d6f2bdf52 (diff) | |
download | sbotools-0e5a36a35f863e91aad439db094607623a0017ca.tar.xz |
bundling Sort::Versions
* Added Sort/Versions.pm and t/versions.t to the MANIFEST.
* Removed dependency on Sort::Versions / perl-Sort-Versions
from both the Makefile.PL andthe sbotools.info files.
* Added Sort::Version's copyright notice to README.
* Made the test prep.pl copy the Sort/Versions.pm to the
test hierarchy.
-rw-r--r-- | SBO-Lib/MANIFEST | 2 | ||||
-rw-r--r-- | SBO-Lib/Makefile.PL | 1 | ||||
-rw-r--r-- | SBO-Lib/README | 6 | ||||
-rw-r--r-- | SBO-Lib/lib/Sort/Versions.pm | 151 | ||||
-rwxr-xr-x | SBO-Lib/t/versions.t | 113 | ||||
-rw-r--r-- | slackbuild/sbotools/sbotools.info | 2 | ||||
-rwxr-xr-x | t/prep.pl | 2 |
7 files changed, 273 insertions, 4 deletions
diff --git a/SBO-Lib/MANIFEST b/SBO-Lib/MANIFEST index c2cad44..eb90507 100644 --- a/SBO-Lib/MANIFEST +++ b/SBO-Lib/MANIFEST @@ -3,4 +3,6 @@ Makefile.PL MANIFEST README t/SBO-Lib.t +t/versions.t lib/SBO/Lib.pm +lib/Sort/Versions.pm diff --git a/SBO-Lib/Makefile.PL b/SBO-Lib/Makefile.PL index ba871ca..45b8dfd 100644 --- a/SBO-Lib/Makefile.PL +++ b/SBO-Lib/Makefile.PL @@ -5,7 +5,6 @@ use ExtUtils::MakeMaker; WriteMakefile( NAME => 'SBO::Lib', VERSION_FROM => 'lib/SBO/Lib.pm', - PREREQ_PM => {'Sort::Versions' => 1.5}, ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT => 'methods, variables, etc for the sbotools pacage', AUTHOR => 'Jacob Pipkin <j@dawnrazor.net>') : ()), diff --git a/SBO-Lib/README b/SBO-Lib/README index 12da295..cada40e 100644 --- a/SBO-Lib/README +++ b/SBO-Lib/README @@ -14,9 +14,11 @@ To install this module type the following: DEPENDENCIES -This module requires these other modules and libraries: +This module bundles Sort::Versions 1.5 which has its own license: - Sort::Versions => 1.5 + The files in this package are copyright Kenneth J. Albanowski, Ed + Avis, and Matt Johnson. This package is free software; you can + redistribute it and/or modify it under the same terms as Perl itself. COPYRIGHT AND LICENCE diff --git a/SBO-Lib/lib/Sort/Versions.pm b/SBO-Lib/lib/Sort/Versions.pm new file mode 100644 index 0000000..56a1ed1 --- /dev/null +++ b/SBO-Lib/lib/Sort/Versions.pm @@ -0,0 +1,151 @@ +#!/usr/bin/perl + +# $Id: Versions.pm,v 1.9 2003/08/24 22:58:14 ed Exp $ + +# Copyright (c) 1996, Kenneth J. Albanowski. All rights reserved. This +# program is free software; you can redistribute it and/or modify it under +# the same terms as Perl itself. + +package Sort::Versions; +use vars '$VERSION'; +$VERSION = '1.5'; + +require Exporter; +@ISA=qw(Exporter); + +@EXPORT=qw(&versions &versioncmp); +@EXPORT_OK=qw(); + +sub versioncmp( $$ ) { + my @A = ($_[0] =~ /([-.]|\d+|[^-.\d]+)/g); + my @B = ($_[1] =~ /([-.]|\d+|[^-.\d]+)/g); + + my ($A, $B); + while (@A and @B) { + $A = shift @A; + $B = shift @B; + if ($A eq '-' and $B eq '-') { + next; + } elsif ( $A eq '-' ) { + return -1; + } elsif ( $B eq '-') { + return 1; + } elsif ($A eq '.' and $B eq '.') { + next; + } elsif ( $A eq '.' ) { + return -1; + } elsif ( $B eq '.' ) { + return 1; + } elsif ($A =~ /^\d+$/ and $B =~ /^\d+$/) { + if ($A =~ /^0/ || $B =~ /^0/) { + return $A cmp $B if $A cmp $B; + } else { + return $A <=> $B if $A <=> $B; + } + } else { + $A = uc $A; + $B = uc $B; + return $A cmp $B if $A cmp $B; + } + } + @A <=> @B; +} + +sub versions() { + my $callerpkg = (caller)[0]; + my $caller_a = "${callerpkg}::a"; + my $caller_b = "${callerpkg}::b"; + no strict 'refs'; + return versioncmp($$caller_a, $$caller_b); +} + +=head1 NAME + +Sort::Versions - a perl 5 module for sorting of revision-like numbers + +=head1 SYNOPSIS + + use Sort::Versions; + @l = sort { versioncmp($a, $b) } qw( 1.2 1.2.0 1.2a.0 1.2.a 1.a 02.a ); + + ... + + use Sort::Versions; + print 'lower' if versioncmp('1.2', '1.2a') == -1; + + ... + + use Sort::Versions; + %h = (1 => 'd', 2 => 'c', 3 => 'b', 4 => 'a'); + @h = sort { versioncmp($h{$a}, $h{$b}) } keys %h; + +=head1 DESCRIPTION + +Sort::Versions allows easy sorting of mixed non-numeric and numeric strings, +like the 'version numbers' that many shared library systems and revision +control packages use. This is quite useful if you are trying to deal with +shared libraries. It can also be applied to applications that intersperse +variable-width numeric fields within text. Other applications can +undoubtedly be found. + +For an explanation of the algorithm, itE<39>s simplest to look at these examples: + + 1.1 < 1.2 + 1.1a < 1.2 + 1.1 < 1.1.1 + 1.1 < 1.1a + 1.1.a < 1.1a + 1 < a + a < b + 1 < 2 + 1.1-3 < 1.1-4 + 1.1-5 < 1.1.6 + +More precisely (but less comprehensibly), the two strings are treated +as subunits delimited by periods or hyphens. Each subunit can contain +any number of groups of digits or non-digits. If digit groups are +being compared on both sides, a numeric comparison is used, otherwise +a ASCII ordering is used. A group or subgroup with more units will win +if all comparisons are equal. A period binds digit groups together +more tightly than a hyphen. + +Some packages use a different style of version numbering: a simple +real number written as a decimal. Sort::Versions has limited support +for this style: when comparing two subunits which are both digit +groups, if either subunit has a leading zero, then both are treated +like digits after a decimal point. So for example: + + 0002 < 1 + 1.06 < 1.5 + +This wonE<39>t always work, because there wonE<39>t always be a leading zero +in real-number style version numbers. There is no way for +Sort::Versions to know which style was intended. But a lot of the time +it will do the right thing. If you are making up version numbers, the +style with (possibly) more than one dot is the style to use. + +=head1 USAGE + +The function C<versioncmp()> takes two arguments and compares them like C<cmp>. +With perl 5.6 or later, you can also use this function directly in sorting: + + @l = sort versioncmp qw(1.1 1.2 1.0.3); + +The function C<versions()> can be used directly as a sort function even on +perl 5.005 and earlier, but its use is deprecated. + +=head1 AUTHOR + +Ed Avis <ed@membled.com> and Matt Johnson <mwj99@doc.ic.ac.uk> for +recent releases; the original author is Kenneth J. Albanowski +<kjahds@kjahds.com>. Thanks to Hack Kampbjørn and Slaven Rezic for +patches and bug reports. + +Copyright (c) 1996, Kenneth J. Albanowski. All rights reserved. This +program is free software; you can redistribute it and/or modify it under the +same terms as Perl itself. + +=cut + +1; + diff --git a/SBO-Lib/t/versions.t b/SBO-Lib/t/versions.t new file mode 100755 index 0000000..af4d406 --- /dev/null +++ b/SBO-Lib/t/versions.t @@ -0,0 +1,113 @@ +#!/usr/bin/perl +#$Id: versions.t,v 1.9 2003/08/24 22:33:03 ed Exp $ + +use strict; +use Sort::Versions; +use Test::More; + +my @tests; + +while(<DATA>) { + if(/^\s*(\S+)\s*([<>])\s*(\S+)\s*$/) { + push @tests, $1,$3 if $2 eq "<"; + push @tests, $3,$1 if $2 eq ">"; + } +} + +plan tests => (@tests / 2 * 3) + 3; + +my @l = sort versions qw(1.2 1.2a); +is($l[0], "1.2"); + +@l = sort { versioncmp($a, $b) } qw(1.2 1.2a); +is($l[0], "1.2"); + +SKIP: { + skip "requires perl 5.6.0", 1 unless ($] >= 5.006); + @l = sort versioncmp qw(1.2 1.2a); + is($l[0], "1.2"); +} + +my $i=4; +while (@tests) { + ($a, $b) = @tests[0, 1]; + + # Test both the versioncmp() and versions() interfaces, in both + # the main package and other packages. + # + is(versions(), -1, "versions($a, $b)"); + $i++; + + is(versioncmp($a, $b), -1, "versioncmp($a, $b)"); + $i++; + + undef $a; undef $b; # just in case + + eval { + package Foo; + use Sort::Versions; + ($a, $b) = @tests[0, 1]; + + if (versions() != -1) { + die "failed versions() in foreign package"; + } + + if (versioncmp($a, $b) != -1) { + die "failed versioncmp() in foreign package"; + } + }; + if ($@) { + fail($@); + } + else { + pass("foreign package tests ($tests[0], $tests[1])"); + } + + shift @tests; shift @tests; +} + + +__END__ + +# Simple . only tests +1.2 < 1.3 +1.2 < 1.2.1 +1.2.1 < 1.3 +1.2 < 1.2a +1.2a < 1.3 +1.2 < 1.2.b +1.2.1 < 1.2a +1.2.b < 1.2a + +# Assorted non-numerics +a < b +a < a.b +a.b < a.c +a.1 < a.a +1 < a +1a < a +1a < 2 + +# Null version point +1..1 < 1.1.1 + +# Leading 0 tests +1 > 0002 +1.5 > 1.06 + +# Handling mixed -. versions +1 < 1-1 +1-1 < 1-2 +1-2 < 1.2 +1-2 < 1.0-1 +1-2 < 1.0 +1-2 < 1.3 +1.2-1 < 1.2a-1 +1.3-4.6-7 < 1.3-4.8 +1.3-4.6-7 < 1.3-4.6.7 +1.3-4a-7 < 1.3-4a-7.4 + +# 'Bug' reported by pgw99 +1.2-1 < 1.2.1-1 +1.2.1-1 < 1.2.1-2 +1.2.1-2 < 1.3.0-1 diff --git a/slackbuild/sbotools/sbotools.info b/slackbuild/sbotools/sbotools.info index d6493e1..359e59f 100644 --- a/slackbuild/sbotools/sbotools.info +++ b/slackbuild/sbotools/sbotools.info @@ -5,6 +5,6 @@ DOWNLOAD="http://dawnrazor.net/wp-content/uploads/2013/03/sbotools-1.6.tar.gz" MD5SUM="cc8a362cdbced4d2c166bc9edb673f4c" DOWNLOAD_x86_64="" MD5SUM_x86_64="" -REQUIRES="perl-Sort-Versions" +REQUIRES="" MAINTAINER="Jacob Pipkin" EMAIL="j@dawnrazor.net" @@ -8,7 +8,9 @@ use Tie::File; chomp(my $pwd = `pwd`); mkdir "$pwd/SBO" unless -d "$pwd/SBO"; +mkdir "$pwd/Sort" unless -d "$pwd/Sort"; copy('../SBO-Lib/lib/SBO/Lib.pm', "$pwd/SBO"); +copy('../SBO-Lib/lib/Sort/Versions.pm', "$pwd/Sort"); open my $write, '>>', "$pwd/SBO/Lib.pm"; |