Path::Node: make type an int not a string
[id3fs.git] / lib / ID3FS / Path / Node.pm
index 3775d38..eb703c2 100644 (file)
@@ -19,6 +19,12 @@ package ID3FS::Path::Node;
 use strict;
 use warnings;
 
+require Exporter;
+use vars qw(@ISA @EXPORT $TYPE_BOOL $TYPE_TAG $TYPE_ARTIST $TYPE_ALBUM $TYPE_FILE);
+@ISA=qw(Exporter);
+@EXPORT=qw($TYPE_BOOL $TYPE_TAG $TYPE_ARTIST $TYPE_ALBUM $TYPE_FILE);
+($TYPE_BOOL, $TYPE_TAG, $TYPE_ARTIST, $TYPE_ALBUM, $TYPE_FILE)=(1..5);
+
 sub new
 {
     my $proto=shift;
@@ -30,10 +36,13 @@ sub new
     $self->{type}=shift;
     $self->{name}=shift;
     $self->{parents_id}=shift;
-    if($self->{type} ne "boolean")
+    if($self->{type} != $TYPE_BOOL)
     {
-       my $table=ucfirst($self->{type});
-       $table .= "s" unless($table=~/s$/);
+       my $table='';
+       if   ($self->{type} == $TYPE_TAG)    { $table="tags";    }
+       elsif($self->{type} == $TYPE_ARTIST) { $table="artists"; }
+       elsif($self->{type} == $TYPE_ALBUM)  { $table="albums";  }
+       elsif($self->{type} == $TYPE_FILE)   { $table="files";   }
        $self->{id}=$db->lookup_id($table, $self->{name}, $self->{parents_id});
        return undef unless(defined($self->{id}));
     }
@@ -69,7 +78,7 @@ sub to_sql
        @outjoins = @joins = ("INNER");
     }
 
-    if($self->type() ne "boolean")
+    if($self->type() != $TYPE_BOOL)
     {
        my $cnt=scalar(@joins)+1;
        $str .= "t" . scalar(@joins) . ".id='" . $self->{id} . "'";
@@ -156,7 +165,7 @@ sub to_sql
 sub used_tags
 {
     my($self)=@_;
-    if($self->type() eq "boolean")
+    if($self->type() == $TYPE_BOOL)
     {
        my @used=();
        push(@used, $self->left()->used_tags())  if($self->left());