change build number calculation to be more accurate
[spider.git] / perl / Prefix.pm
index 8ea62b87fbda9e742fd0a481b925e753a9b2c65e..954490fcf41e2798ad39ba6c6951b89002922dd5 100644 (file)
@@ -8,13 +8,20 @@
 
 package Prefix;
 
-use Carp;
+use IO::File;
 use DXVars;
 use DB_File;
 use Data::Dumper;
-use Carp;
+use DXDebug;
 
 use strict;
+
+use vars qw($VERSION $BRANCH);
+$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
+$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0;
+$main::build += $VERSION;
+$main::branch += $BRANCH;
+
 use vars qw($db  %prefix_loc %pre);
 
 $db = undef;                                   # the DB_File handle
@@ -40,7 +47,7 @@ sub load
 sub store
 {
        my ($k, $l);
-       my $fh = new FileHandle;
+       my $fh = new IO::File;
        my $fn = "$main::data/prefix_data.pl";
   
        confess "Prefix system not started" if !$db;
@@ -149,10 +156,12 @@ sub extract
 
        # remove any /0-9 /P /A /M /MM /AM suffixes etc
        if (@parts > 1) {
+               $p = $parts[0];
+               shift @parts if $p =~ /^(WEB|NET)$/o;
                $p = $parts[$#parts];
-               pop @parts if $p =~ /^(\d+|[PABM]|AM|MM|BCN|SIX|Q\w+)$/o;
+               pop @parts if $p =~ /^(\d+|[JPABM]|AM|MM|BCN|JOTA|SIX|WEB|NET|Q\w+)$/o;
                $p = $parts[$#parts];
-               pop @parts if $p =~ /^(\d+|[PABM]|AM|MM|BCN|SIX|Q\w+)$/o;
+               pop @parts if $p =~ /^(\d+|[JPABM]|AM|MM|BCN|JOTA|SIX|WEB|NET|Q\w+)$/o;
   
                # can we resolve them by direct lookup
                foreach $p (@parts) {
@@ -186,6 +195,7 @@ my %valid = (
                         itu => '0,ITU',
                         cq => '0,CQ',
                         utcoff => '0,UTC offset',
+                        cont => '0,Continent',
                        );
 
 no strict;
@@ -198,6 +208,9 @@ sub AUTOLOAD
        $name =~ s/.*:://o;
   
        confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
+       # this clever line of code creates a subroutine which takes over from autoload
+       # from OO Perl - Conway
+       *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ;
        if (@_) {
                $self->{$name} = shift;
        }