## CatalogNumList.pm A version of List that correctly sorts Taonga catalogue numbers
package CatalogNumList;

use List;

use strict;

sub BEGIN {
    @CatalogNumList::ISA = ('List');
}

# all I want to do with this classifier is sort numbers like 3q1 and
# 3q1/2a so that the numeric parts are sorted numerically.
sub alpha_numeric_cmp
{
    my ($self,$a,$b) = @_;
    my ($a1, $a2, $a3) = $a =~ m@^3q(\d+)(?:/(\d+)(.*))?$@;
    my ($b1, $b2, $b3) = $b =~ m@^3q(\d+)(?:/(\d+)(.*))?$@;

    if ($a1 && $b1) {
	if ($a1 != $b1) {
	    return ($a1 <=> $b1);
	}
	if ($a2 && $b2) {
	    if ($a2 != $b2) {
		return ($a2 <=> $b2);
	    }
	    return ($a3 cmp $b3);
	}
    }
    return $a cmp $b;
}



1;
