STL now prints file name on fail open
[migration-tools.git] / Equinox-Migration / lib / Equinox / Migration / SimpleTagList.pm
index 25ef631..ffe3591 100644 (file)
@@ -9,11 +9,11 @@ Equinox::Migration::SimpleTagList - Generate taglist from file
 
 =head1 VERSION
 
-Version 1.000
+Version 1.001
 
 =cut
 
-our $VERSION = '1.000';
+our $VERSION = '1.001';
 
 
 =head1 SYNOPSIS
@@ -40,8 +40,8 @@ or
 
 =head2 new
 
-Takes one argument, optional argument, C<file>. If this is speficied,
-the tag list will be populated as per that file on instantiation.
+Takes one optional argument, C<file>. If this is speficied, the tag
+list will be populated as per that file on instantiation.
 
 Returns a E::M::STL object.
 
@@ -58,11 +58,12 @@ sub new {
 
     if ($args{file}) {
         if (-r $args{file}) {
-            $self->{conf}{file} = $args{file};
-            $self->generate;
+            $self->generate($args{file});
         } else {
-            die "Can't open tags file: $!\n";
+            die "Can't open tags file '", $args{file}, "': $!\n";
         }
+    }elsif ($args{str}) {
+        $self->generate($args{str},'scalar');
     }
 
     return $self;
@@ -105,16 +106,24 @@ numerically by tag).
 sub as_listref { my ($self) = @_; return [ sort {$a <=> $b} keys %{$self->{tags}} ] }
 
 sub generate {
-    my ($self) = @_;
+    my ($self, $file, $scalar) = @_;
 
-    open TAGFILE, '<', $self->{conf}{file};
+    if ($scalar) {
+        open TAGFILE, '<', \$file;
+    } else {
+        open TAGFILE, '<', $file;
+    }
     while (<TAGFILE>) {
+        next if m/^#/;
+        next if m/^\s*\n$/;
+
         $self->{conf}{lastwasrange} = 0;
         $self->{conf}{range}{high}  = 0;
         $self->{conf}{range}{low}   = 0;
 
         my @chunks = split /\s+/;
         while (my $chunk = shift @chunks) {
+            last if ($chunk =~ /^#/);
 
             # single values
             if ($chunk =~ /^\d{1,3}$/) {
@@ -178,6 +187,8 @@ sub add_tag {
     my ($self, $tag) = @_;
     $tag =~ s/^0+//;
 
+    die "Values must be numeric\n" if ($tag =~ /[^\d\-]/);
+
     die "Values must be valid tags (0-999)\n"
       unless ($tag >= 0 and $tag <= 999);
 
@@ -216,7 +227,7 @@ Please report any bugs or feature requests to the above email address.
 
 You can find documentation for this module with the perldoc command.
 
-    perldoc Equinox::Migration::TrashTags
+    perldoc Equinox::Migration::SimpleTagList
 
 
 =head1 COPYRIGHT & LICENSE