Index: /trunk/PS-IPP-Config/lib/PS/IPP/Config.pm
===================================================================
--- /trunk/PS-IPP-Config/lib/PS/IPP/Config.pm	(revision 15183)
+++ /trunk/PS-IPP-Config/lib/PS/IPP/Config.pm	(revision 15184)
@@ -1,5 +1,5 @@
 # Copyright (c) 2006  Paul Price, Joshua Hoblitt
 #
-# $Id: Config.pm,v 1.69 2007-09-07 21:39:58 price Exp $
+# $Id: Config.pm,v 1.70 2007-10-03 22:15:02 price Exp $
 
 package PS::IPP::Config;
@@ -87,4 +87,5 @@
 	path => $path,		# Path
 	camera => undef,	# Camera configuration
+	filerules => undef,	# File rules from the camera configuration
 	rejection => undef,	# Rejection data
 	_ipprc => $mdc		# The parsed configuration
@@ -654,14 +655,41 @@
     }
 
-    my $camera = $self->{camera}; # Camera configuration
-    unless (defined $camera) {
-	carp "Camera has not yet been defined.\n";
-	return undef;
-    }
-
-    my $filerules = metadataLookupMD($camera, 'FILERULES');	# File rules
-    unless (defined $filerules) {
-	carp "Can't find FILERULES list in camera configuration.\n";
-	return undef;
+    my $filerules;		# File rules
+    if (defined $self->{filerules}) {
+	$filerules = $self->{filerules};
+    } else {
+	# Get the file rules from the camera configuration
+
+	my $camera = $self->{camera}; # Camera configuration
+	unless (defined $camera) {
+	    carp "Camera has not yet been defined.\n";
+	    return undef;
+	}
+	
+	$filerules = metadataLookup($camera, 'FILERULES');	# File rules
+	unless (defined $filerules) {
+	    carp "Can't find FILERULES list in camera configuration.\n";
+	    return undef;
+	}
+	
+	if ($filerules->{class} eq "scalar" and $filerules->{type} eq "STR") {
+	    # Allow indirection to a file
+	    my $filename = $self->_find_config($filerules->{value}); # Resolved filename
+	    # Read the file
+	    my $file;		# File handle
+	    unless (open $file, $filename) {
+		carp "Unable to open filerules file $filename: $!";
+		exit($PS_EXIT_CONFIG_ERROR);
+	    }
+	    my @contents = <$file>;
+	    close $file;
+	    $filerules = $parser->parse( join '', @contents);
+	} elsif ($filerules->{class} eq "metadata") {
+	    $filerules = $filerules->{value};
+	} else {
+	    carp "Can't interpret FILERULES in camera configuration.\n";
+	    return undef;
+	}
+	$self->{filerules} = $filerules;
     }
 
@@ -845,6 +873,5 @@
 }
 
-# Lookup the metadata, checking the type is STR
-sub metadataLookupStr
+sub metadataLookup
 {
     my $mdc = shift;		# Metadata config to look up
@@ -859,6 +886,5 @@
     foreach my $item (@$mdc) {
 	if ($item->{name} eq $name) {
-	    carp "$name within metadata is not of type STR.\n" unless $item->{type} eq "STR";
-	    return $item->{value};
+	    return $item;
 	}
     }
@@ -867,26 +893,24 @@
     return undef;
 }
+   
+
+# Lookup the metadata, checking the type is STR
+sub metadataLookupStr
+{
+    my $item = metadataLookup(@_);
+    return undef if not defined $item;
+    my $name = shift;		# Name of item
+    carp "$name within metadata is not of type STR.\n" unless $item->{type} eq "STR";
+    return $item->{value};
+}
 
 # Lookup the metadata, checking the type is MD
 sub metadataLookupMD
 {
-    my $mdc = shift;		# Metadata config to look up
-    my $name = shift;		# Name of item to look ip
-
-    unless (defined $mdc and defined $name) {
-	carp "Programming error";
-	exit($PS_EXIT_PROG_ERROR);
-    }
-
-    # Iterate through the array of hashes
-    foreach my $item (@$mdc) {
-	if ($item->{name} eq $name) {
-	    carp "$name within metadata is not of type METADATA.\n" unless $item->{class} eq "metadata";
-	    return $item->{value};
-	}
-    }
-
-    carp "Unable to find $name within metadata.\n";
-    return undef;
+    my $item = metadataLookup(@_);
+    return undef if not defined $item;
+    my $name = shift;		# Name of item
+    carp "$name within metadata is not of type METADATA.\n" unless $item->{class} eq "metadata";
+    return $item->{value};
 }
 
@@ -894,22 +918,9 @@
 sub metadataLookupBool
 {
-    my $mdc = shift;		# Metadata config to look up
-    my $name = shift;		# Name of item to look ip
-
-    unless (defined $mdc and defined $name) {
-	carp "Programming error";
-	exit($PS_EXIT_PROG_ERROR);
-    }
-
-    # Iterate through the array of hashes
-    foreach my $item (@$mdc) {
-	if ($item->{name} eq $name) {
-	    carp "$name within metadata is not of type BOOL.\n" unless $item->{type} eq "BOOL";
-	    return $item->{value};
-	}
-    }
-
-    carp "Unable to find $name within metadata.\n";
-    return undef;
+    my $item = metadataLookup(@_);
+    return undef if not defined $item;
+    my $name = shift;		# Name of item
+    carp "$name within metadata is not of type BOOL.\n" unless $item->{type} eq "BOOL";
+    return $item->{value};
 }
 
