Index: /trunk/PS-IPP-Config/lib/PS/IPP/Config.pm
===================================================================
--- /trunk/PS-IPP-Config/lib/PS/IPP/Config.pm	(revision 9168)
+++ /trunk/PS-IPP-Config/lib/PS/IPP/Config.pm	(revision 9168)
@@ -0,0 +1,79 @@
+# Copyright (c) 2006  Paul Price, Joshua Hoblitt
+#
+# $Id: Config.pm,v 1.1 2006-10-04 01:45:47 price Exp $
+
+package PS::IPP::Config;
+
+use strict;
+use warnings FATAL => qw( all );
+
+our $VERSION = '0.01';
+
+use Carp qw( carp croak );
+use PS::IPP::Metadata::Config;
+use Getopt::Long qw( GetOptions :config gnu_getopt pass_through ); # Set pass_through so we don't kill @ARGV
+
+use base qw( Class::Accessor::Fast );
+__PACKAGE__->mk_accessors( qw( path workdir ) );
+
+#$::RD_TRACE = 1;
+#$::RD_HINT = 1;
+#use Data::Dumper;
+
+# Given a parsed metadata, parse it into an array of hashes
+sub new {
+    my $class = shift;		# Class name
+
+    # Get location of ipprc file
+    my $name;			# Name of ipprc file
+    GetOptions( 'site=s' => \$name );
+    $name = $ENV{PS_SITE} if not defined $name;
+    $name = $ENV{HOME} . '/.ipprc' if not defined $name;
+
+    open my $file, $name or croak "Unable to open ipprc file $name: $!";
+    my @contents = <$file>;	# Contents of the ipprc file
+    close $file;
+
+    my $parser = PS::IPP::Metadata::Config->new; # Parser for ipprc file
+    my $mdc = $parser->parse( join '', @contents); # The parsed metadata config
+
+    my $path = _mdLookupStr($mdc, 'PATH'); # The path
+    my $workdir = _mdLookupStr($mdc, 'WORKDIR'); # The working directory
+
+    croak "PATH is not set in $name\n" unless defined $path;
+    croak "WORKDIR is not set in $name\n" unless defined $workdir;
+
+    my $self = {
+	path => $path,		# Path
+	workdir => $workdir,	# Working directory
+	_ipprc => $mdc		# The parsed configuration
+	};
+
+    bless $self, $class;
+    return $self;
+
+}
+
+# Lookup the metadata, checking the type
+sub _mdLookupStr
+{
+    my $mdc = shift;		# Metadata config to look up
+    my $name = shift;		# Name of item to look up
+
+    # Iterate through the array of hashes
+    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};
+	}
+    }
+
+    carp "Unable to find $name within metadata.\n";
+    return undef;
+}
+
+
+1;
+
+__END__;
+
