ZConf::DBI - Stores DBI connection information in ZConf.


ZConf-DBI documentation Contained in the ZConf-DBI distribution.

Index


Code Index:

NAME

Top

ZConf::DBI - Stores DBI connection information in ZConf.

VERSION

Top

Version 0.0.1

SYNOPSIS

Top

    use ZConf::DBI;
    use DBI::Shell;

    my $foo=ZConf::DBI->new;

    my $ds=$foo->getDS('tigerline');
    my $user=$foo->getDSuser('tigerline');
    my $pass=$foo->getDSpass('tigerline');

    DBI::Shell->new($ds, $user, $pass)->run;

METHODS

Top

new

This initiates the object.

hash values

zconf

If this is defined, it will be used instead of creating a new ZConf object.

addDS

This adds a new data source.

args hash

The only required is 'ds'. Any thing else can be undef.

attr

This hash reference contains any attributes one wishes to pass to the new connections.

ds

This is the data source string.

name

The name of the new data source.

pass

This is the password to use.

This can be undefined.

user

This is the the user to use.

This can be undefined.

    $foo->addDS({ds=>$datasource, user=>$user, pass=>$pass, name=>'some name'  });
    if($foo->error){
        print "Error!\n";
    }

connect

This connects and returns the database handle formed by DBI->connect.

This just returns the database handle and does not check if succedded or not.

Only one arguement is required and it is the name of the data source.

    my $dbh=$foo->connect('someDS');
    if($foo->error){
        print "Error!\n";
    }

dataSourceExists

This checks if the specified data source exists or not.

Only one arguement is taken and it is the name of data source to check for.

The returned value is either a Perl boolean value.

    if(!$foo->dataSourceExists('bar')){
        print "The data source 'bar' does not exist\n";
    }

delDS

This removes a data source.

delSet

This removes the specified ZConf set.

    $foo->delSet('someSet');
    if($foo->error){
        print "Error!\n";
    }

error

Returns the current error code and true if there is an error.

If there is no error, undef is returned.

    my $error=$foo->error;
    if($error){
        print 'error code: '.$error."\n";
    }

errorString

Returns the error string if there is one. If there is not, it will return ''.

    my $error=$foo->error;
    if($error){
        print 'error code:'.$error.': '.$foo->errorString."\n";
    }

getDS

This gets the data source value for a data source.

Only one arguement is required and is the name of the data source.

    my $ds=$foo->getDS("someDS");
    if($foo->{error}){
        print "Error!\n";
    }

getDSattrs

This gets the pass for a data source.

This can potentially be undef.

Only one arguement is required and is the name of the data source.

    my %attrs=$foo->getDS("someDS");
    if($foo->error){
        print "Error!\n";
    }

getDSpass

This gets the pass for a data source.

This can potentially be undef.

Only one arguement is required and is the name of the data source.

    my $ds=$foo->getDS("someDS");
    if($foo->error){
        print "Error!\n";
    }

getDSuser

This gets the user for a data source.

This can potentially be undef.

Only one arguement is required and is the name of the data source.

    my $ds=$foo->getDS("someDS");
    if($foo->error){
        print "Error!\n";
    }

init

This initiates a new set. If a set already exists, it will be overwritten.

If the set specified is undefined, the default will be used.

The set is not automatically read.

    $foo->init($set);
    if($foo->error){
        print "Error!\n";
    }

listDSs

This lists the available data sources.

No arguements are taken.

The returned value is a array of available data sources.

    my @datasources=$foo->listDSs;
    if($foo->error){
        print "Error!\n";
    }else{
        use Data::Dumper;
        print Dumper(\@daasources);
    }

listSets

This lists the available sets for the ZConf config.

    my @sets=$foo->listSets;
    if($foo->error){
        print "Error!\n";
    }

readSet

This reads a specified ZConf set.

If no set is specified, the default is used.

    $foo->readSet('someSet');
    if($foo->error){
        print "Error!\n";
    }

setDS

This changes the data source value for a already setup data source.

Two arguements are required. The first is the data source name and the second is the data source.

    $foo->setDS('someDS', 'DBI:mysql:databasename');
    if($foo->error){
        print "Error!\n";
    }

setDSattr

This changes the data source value for a already setup data source.

Three arguements are required. The first is the data source name, second is the data source, and the third is the value.

If the value is undefined, the attribute is removed.

    $foo->setDS('someDS', 'someAttr', 'someValue');
    if($foo->error){
        print "Error!\n";
    }

setDSpass

This changes the password value for a already setup data source.

Two arguements are required. The first is the data source name and the second is the password.

    $foo->setDS('someDS', 'somePass');
    if($foo->error){
        print "Error!\n";
    }

setDSuser

This changes the user value for a already setup data source.

Two arguements are required. The first is the data source name and the second is the user.

    $foo->setDS('someDS', 'someUser');
    if($foo->error){
        print "Error!\n";
    }

errorblank

This blanks the error storage and is only meant for internal usage.

It does the following.

    $self->{error}=undef;
    $self->{errorString}="";

ERROR CODES

Top

To fetch the error code, use the method 'error'.

1

ZConf errored.

2

Data source name not specified.

3

Data source not defined.

4

The data source already exists.

5

The data source name contains a '/'.

6

The data source does not exist.

7

Data source does not exist.

8

No attribute specified.

9

No value specified.

10

No user specified.

11

No password specified.

ZCONF KEYS

Top

datasources/<data source name>/ds

This is the data source string for a data source.

This is required.

datasources/<data source name>/user

This is the user for a data source.

This may not be defined.

datasources/<data source name>/pass

This is the password for a data source.

This may not be defined.

datasources/<data source name>/attr/<attribute name>

This contains any attributes for a data source.

AUTHOR

Top

Zane C. Bowers, <vvelox at vvelox.net>

BUGS

Top

Please report any bugs or feature requests to bug-zconf-devtemplate at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ZConf-DBI. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc ZConf::DBI




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=ZConf-DBI

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/ZConf-DBI

* CPAN Ratings

http://cpanratings.perl.org/d/ZConf-DBI

* Search CPAN

http://search.cpan.org/dist/ZConf-DBI/

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


ZConf-DBI documentation Contained in the ZConf-DBI distribution.
package ZConf::DBI;

use warnings;
use strict;
use ZConf;

our $VERSION = '0.0.1';

sub new{
	my %args;
	if(defined($_[1])){
		%args= %{$_[1]};
	}
	my $function='new';

	my $self={error=>undef,
			  perror=>undef,
			  errorString=>undef,
			  zconfconfig=>'DBI',
			  module=>'ZConf-DBI',
			  };
	bless $self;
	
	#get the ZConf object
	if (!defined($args{zconf})) {
		#creates the ZConf object
		$self->{zconf}=ZConf->new();
		if(defined($self->{zconf}->{error})){
			$self->{error}=1;
			$self->{perror}=1;
			$self->{errorString}="Could not initiate ZConf. It failed with '"
			                      .$self->{zconf}->{error}."', '".
			                      $self->{zconf}->{errorString}."'";
			warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
			return $self;
		}
	}else {
		$self->{zconf}=$args{zconf};
	}

	#check if the config exists
	my $returned = $self->{zconf}->configExists($self->{zconfconfig});
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{perror}=1;
		$self->{errorString}="Checking if '".$self->{zconfconfig}."' exists failed. error='".
		                     $self->{zconf}->{error}."', errorString='".
		                     $self->{zconf}->{errorString}."'";
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return $self;
	}

	#initiate the config if it does not exist
	if (!$returned) {
		#create the config
		$self->{zconf}->createConfig($self->{zconfconfig});
		if ($self->{zconf}->{error}) {
			$self->{error}=1;
			$self->{perror}=1;
			$self->{errorString}="Checking if '".$self."' exists failed. error='".
		                         $self->{zconf}->{error}."', errorString='".
		                         $self->{zconf}->{errorString}."'";
			warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
			return $self;
		}

		#init it
		$self->init;
		if ($self->{zconf}->{error}) {
			$self->{perror}=1;
			$self->{errorString}='Init failed.';
			warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
			return $self;
		}
	}else {
		#if we have a set, make sure we also have a set that will be loaded
		$returned=$self->{zconf}->defaultSetExists($self->{zconfconfig});
		if ($self->{zconf}->{error}) {
			$self->{error}=1;
			$self->{perror}=1;
			$self->{errorString}="Checking if '".$self."' exists failed. error='".
		                         $self->{zconf}->{error}."', errorString='".
		                         $self->{zconf}->{errorString}."'";
			warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
			return $self;
		}

		#initiliaze a the default set if needed.
		if (!$returned) {
			#init it
			$self->init;
			if ($self->{zconf}->{error}) {
				$self->{perror}=1;
				$self->{errorString}='Init failed.';
				warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
				return $self;
			}
		}
	}


	#read the config
	$self->{zconf}->read({config=>$self->{zconfconfig}});
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{perror}=1;
		$self->{errorString}="Checking if the default set for '".$self->{zconfconfig}."' exists failed. error='".
		                     $self->{zconf}->{error}."', errorString='".
		                     $self->{zconf}->{errorString}."'";
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return $self
	}

	return $self;
}

sub addDS{
	my $self=$_[0];
	my %args;
	%args=%{$_[1]};
	my $function='addDataSource';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}	

	if (!defined( $args{name} )) {
		$self->{error}=2;
		$self->{errorString}='No name specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	if (!defined( $args{ds} )) {
		$self->{error}=3;
		$self->{errorString}='No data source specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#make sure it does not exist already
	my $dsExists=$self->dataSourceExists( $args{name} );
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': dataSourceExists errored');
		return undef;
	}
	if ($dsExists) {
		$self->{error}=4;
		$self->{errorString}='The data source "'.$args{name}.'" already exists';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#make sure the name does not have a / in it
	if ($args{name} =~ /\//) {
		$self->{error}=5;
		$self->{errorString}='The data source name, "'.$args{name}.'", contains a "/"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#adds the datasource
	$self->{zconf}->setVar('DBI', 'datasources/'.$args{name}.'/ds', $args{ds});
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf setVar failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#Adds the username if needed.
	#There is no need to error check this as it will work if the last setVar worked
	if (defined( $args{user} )) {
		$self->{zconf}->setVar('DBI', 'datasources/'.$args{name}.'/user', $args{user});
	}
	#Adds the password if needed.
	if (defined( $args{pass} )) {
		$self->{zconf}->setVar('DBI', 'datasources/'.$args{name}.'/pass', $args{pass});
	}

	#handles and attributes if specified
	if (defined( $args{attr} )) {

		#adds each key
		my @keys=keys( %{ $args{attr} } );
		my $int=0;
		while (defined( $keys[$int] )) {
			$self->{zconf}->setVar('DBI', 'datasources/'.$args{name}.'/attr/'.$keys[$int] , $args{attr}{$keys[$int]} );
			$int++;
		}
	}

	#saves it
	$self->{zconf}->writeSetFromLoadedConfig({config=>$self->{zconfconfig}});
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf writeSetFromHash failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return $self;
	}

	return 1;
}

sub connect{
	my $self=$_[0];
	my $dsName=$_[1];
	my $function='connect';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#makes sure a DS name was specified
	if (!defined( $dsName )) {
		$self->{error}=2;
		$self->{errorString}='No DS name specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#make sure it does not exist already
	my $dsExists=$self->dataSourceExists( $dsName );
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': dataSourceExists errored');
		return undef;
	}
	if (!$dsExists) {
		$self->{error}=7;
		$self->{errorString}='The data source "'.$dsName.'" does not exist';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#fetches the data source
	my $ds=$self->getDS($dsName);
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': getDS errored');
		return undef;
	}

	#fetches the user for the data source
	my $user=$self->getDSuser($dsName);
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': getDSuser errored');
		return undef;
	}

	#fetches the user for the data source
	my $pass=$self->getDSpass($dsName);
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': getDSuser errored');
		return undef;
	}

	#fetches the user for the data source
	my %attrs=$self->getDSattrs($dsName);
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': getDSattrs errored');
		return undef;
	}

	#connect and return the results
	use DBI;
	return DBI->connect($ds, $user, $pass, \%attrs);
}

sub dataSourceExists{
	my $self=$_[0];
	my $datasource=$_[1];
	my $function='dataSourceExists';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#makes sure the data source exists
	if (!defined( $datasource )) {
		$self->{error}=2;
		$self->{errorString}='No name specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#gets a list of data sources
	my @datasources=$self->listDSs;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': listDSs errored');
		return undef;
	}

	#run through checking for a match
	my $int=0;
	while (defined( $datasources[$int] )) {
		if ($datasources[$int] eq $datasource) {
			return 1;
		}

		$int++;
	}

	return undef;
}

sub delDS{
	my $self=$_[0];
	my $dsName=$_[1];
	my $function='delDS';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#makes sure a DS name was specified
	if (!defined( $dsName )) {
		$self->{error}=2;
		$self->{errorString}='No DS name specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#make sure it does not exist already
	my $dsExists=$self->dataSourceExists( $dsName );
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': dataSourceExists errored');
		return undef;
	}
	if (!$dsExists) {
		$self->{error}=7;
		$self->{errorString}='The data source "'.$dsName.'" does not exist';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	my @deleted=$self->{zconf}->regexVarDel( $self->{zconfconfig}, '^datasources\/'.quotemeta($dsName).'\/' );
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf regexVarDel failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#saves it
	$self->{zconf}->writeSetFromLoadedConfig({config=>$self->{zconfconfig}});
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf writeSetFromHash failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return $self;
	}

	return 1;
}

sub delSet{
	my $self=$_[0];
	my $set=$_[1];
	my $function='delSet';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	$self->{zconf}->delSet($self->{zconfconfg}, $set);
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf getAvailableSets failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}


	return 1;
}

sub error{
    return $_[0]->{error};
}

sub errorString{
    return $_[0]->{errorString};
}

sub getDS{
	my $self=$_[0];
	my $dsName=$_[1];
	my $function='getDS';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#makes sure a DS name was specified
	if (!defined( $dsName )) {
		$self->{error}=2;
		$self->{errorString}='No DS name specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#fetches them
	my %vars=$self->{zconf}->regexVarGet( $self->{zconfconfig}, '^datasources/'.$dsName.'/ds$' );
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf regexVarGet failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#makes sure it it exists... if it does not it errors
	if (!defined( $vars{ 'datasources/'.$dsName.'/ds' } )) {
		$self->{error}=6;
		$self->{errorString}='The data source, "'.$dsName.'", does not exist';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	return $vars{ 'datasources/'.$dsName.'/ds' };
}

sub getDSattrs{
	my $self=$_[0];
	my $dsName=$_[1];
	my $function='getDSpass';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#makes sure a DS name was specified
	if (!defined( $dsName )) {
		$self->{error}=2;
		$self->{errorString}='No DS name specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#fetches them
	my %vars=$self->{zconf}->regexVarGet( $self->{zconfconfig}, '^datasources/'.$dsName.'/' );
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf regexVarGet failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#makes sure it it exists... if it does not it errors
	if (!defined( $vars{ 'datasources/'.$dsName.'/ds' } )) {
		$self->{error}=6;
		$self->{errorString}='The data source, "'.$dsName.'", does not exist';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#process each returned key
	my @keys=keys(%vars);
	my $int=0;
	my %toreturn;
	my $base='^datasources/'.$dsName.'/attr/';
	while (defined( $keys[$int] )) {
		if ($keys[$int] =~ /$base/) {
			my $newkey=$keys[$int];
			$newkey=~s/$base//;
			$toreturn{$newkey}=$vars{$keys[$int]};
		}

		$int++;
	}

	return %toreturn;
}

sub getDSpass{
	my $self=$_[0];
	my $dsName=$_[1];
	my $function='getDSpass';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#makes sure a DS name was specified
	if (!defined( $dsName )) {
		$self->{error}=2;
		$self->{errorString}='No DS name specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#fetches them
	my %vars=$self->{zconf}->regexVarGet( $self->{zconfconfig}, '^datasources/'.$dsName.'/' );
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf regexVarGet failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#makes sure it it exists... if it does not it errors
	if (!defined( $vars{ 'datasources/'.$dsName.'/ds' } )) {
		$self->{error}=6;
		$self->{errorString}='The data source, "'.$dsName.'", does not exist';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#return undef if it does not exist
	if (!defined( $vars{ 'datasources/'.$dsName.'/pass' } )) {
		return undef;		
	}

	return $vars{ 'datasources/'.$dsName.'/pass' };
}

sub getDSuser{
	my $self=$_[0];
	my $dsName=$_[1];
	my $function='getDSuser';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#makes sure a DS name was specified
	if (!defined( $dsName )) {
		$self->{error}=2;
		$self->{errorString}='No DS name specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#fetches them
	my %vars=$self->{zconf}->regexVarGet( $self->{zconfconfig}, '^datasources/'.$dsName.'/' );
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf regexVarGet failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#makes sure it it exists... if it does not it errors
	if (!defined( $vars{ 'datasources/'.$dsName.'/ds' } )) {
		$self->{error}=6;
		$self->{errorString}='The data source, "'.$dsName.'", does not exist';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#return undef if it does not exist
	if (!defined( $vars{ 'datasources/'.$dsName.'/user' } )) {
		return undef;		
	}

	return $vars{ 'datasources/'.$dsName.'/user' };
}

sub init{
	my $self=$_[0];
	my $set=$_[1];
	my $function='init';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#the that what will be used for creating the new ZConf config
	my %hash;

	$self->{zconf}->writeSetFromHash({config=>$self->{zconfconfig}, set=>$set},\%hash);
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf writeSetFromHash failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return $self;
	}

	return 1;
}

sub listDSs{
	my $self=$_[0];
	my $function='listDSs';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#searches for datasources
	my @matched=$self->{zconf}->regexVarSearch($self->{zconfconfig}, '^datasources\/');
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf regexVarSearch failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return $self;
	}

	#process the found data sources
	my %found; #provides easy holding for ones found to prevent duplicates
	my $int=0; #used for running through each one
	while (defined( $matched[$int] )) {
		my @split=split( /\//, $matched[$int] );
		if (defined( $split[1] )) {
			$found{$split[1]}=1;
		}

		$int++;
	}

	#returns the found data sources, the keys in %found
	return keys(%found);
}

sub listSets{
	my $self=$_[0];
	my $function='listSets';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	my @sets=$self->{zconf}->getAvailableSets($self->{zconfconfig});
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf getAvailableSets failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return $self;
	}

	return @sets;
}

sub readSet{
	my $self=$_[0];
	my $set=$_[1];
	my $function='readSet';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#read the config
	$self->{zconf}->read({config=>$self->{zconfconfig}, set=>$set});
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='Failed to read the set. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return $self;
	}

	return 1;
}

sub setDS{
	my $self=$_[0];
	my $dsName=$_[1];
	my $ds=$_[2];
	my $function='getDS';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#makes sure a DS name was specified
	if (!defined( $dsName )) {
		$self->{error}=2;
		$self->{errorString}='No DS name specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#makes sure a DS name was specified
	if (!defined( $ds )) {
		$self->{error}=3;
		$self->{errorString}='No data source specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#make sure it does not exist already
	my $dsExists=$self->dataSourceExists( $dsName );
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': dataSourceExists errored');
		return undef;
	}
	if (!$dsExists) {
		$self->{error}=7;
		$self->{errorString}='The data source "'.$dsName.'" does not exist';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#set the variable
	my $var='datasources/'.$dsName.'/ds';
	$self->{zconf}->setVar($self->{zconfconfig}, $var, $ds);
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf setVar failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#saves it
	$self->{zconf}->writeSetFromLoadedConfig({config=>$self->{zconfconfig}});
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf writeSetFromHash failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return $self;
	}

	return 1;
}

sub setDSattr{
	my $self=$_[0];
	my $dsName=$_[1];
	my $attr=$_[2];
	my $value=$_[3];
	my $function='getDSattr';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#makes sure a DS name was specified
	if (!defined( $dsName )) {
		$self->{error}=2;
		$self->{errorString}='No DS name specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#makes sure a DS name was specified
	if (!defined( $attr )) {
		$self->{error}=8;
		$self->{errorString}='No attribute specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#make sure it does not exist already
	my $dsExists=$self->dataSourceExists( $dsName );
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': dataSourceExists errored');
		return undef;
	}
	if (!$dsExists) {
		$self->{error}=7;
		$self->{errorString}='The data source "'.$dsName.'" does not exist';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#removes it if the value is not defined...
	if (!defined( $value )) {
		my $rm='^datasources/'.$dsName.'/attr/'.$attr.'$';
		$self->{zconf}->regexVarDel($self->{zconfconfig}, $rm);
		if ($self->{zconf}->{error}) {
			$self->{error}=1;
			$self->{errorString}='ZConf setVar failed. error="'.
		                         $self->{zconf}->{error}.'", errorString="'.
		                         $self->{zconf}->{errorString}.'"';
			warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
			return undef;
		}

		return 1;
	}

	#set the variable
	my $var='datasources/'.$dsName.'/attr/'.$attr;
	$self->{zconf}->setVar($self->{zconfconfig}, $var, $value);
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf setVar failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#saves it
	$self->{zconf}->writeSetFromLoadedConfig({config=>$self->{zconfconfig}});
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf writeSetFromHash failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return $self;
	}

	return 1;
}

sub setDSpass{
	my $self=$_[0];
	my $dsName=$_[1];
	my $pass=$_[2];
	my $function='getDSpass';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#makes sure a DS name was specified
	if (!defined( $dsName )) {
		$self->{error}=2;
		$self->{errorString}='No DS name specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#makes sure a user name is specified
	if (!defined( $pass )) {
		$self->{error}=11;
		$self->{errorString}='No pass specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#make sure it does not exist already
	my $dsExists=$self->dataSourceExists( $dsName );
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': dataSourceExists errored');
		return undef;
	}
	if (!$dsExists) {
		$self->{error}=7;
		$self->{errorString}='The data source "'.$dsName.'" does not exist';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#set the variable
	my $var='datasources/'.$dsName.'/pass';
	$self->{zconf}->setVar($self->{zconfconfig}, $var, $pass);
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf setVar failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#saves it
	$self->{zconf}->writeSetFromLoadedConfig({config=>$self->{zconfconfig}});
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf writeSetFromHash failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return $self;
	}

	return 1;
}

sub setDSuser{
	my $self=$_[0];
	my $dsName=$_[1];
	my $user=$_[2];
	my $function='getDSuser';

	$self->errorblank;
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
		return undef;
	}

	#makes sure a DS name was specified
	if (!defined( $dsName )) {
		$self->{error}=2;
		$self->{errorString}='No DS name specified';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;		
	}

	#make sure it does not exist already
	my $dsExists=$self->dataSourceExists( $dsName );
	if ($self->{error}) {
		warn($self->{module}.' '.$function.': dataSourceExists errored');
		return undef;
	}
	if (!$dsExists) {
		$self->{error}=7;
		$self->{errorString}='The data source "'.$dsName.'" does not exist';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#set the variable
	my $var='datasources/'.$dsName.'/user';
	$self->{zconf}->setVar($self->{zconfconfig}, $var, $user);
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf setVar failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return undef;
	}

	#saves it
	$self->{zconf}->writeSetFromLoadedConfig({config=>$self->{zconfconfig}});
	if ($self->{zconf}->{error}) {
		$self->{error}=1;
		$self->{errorString}='ZConf writeSetFromHash failed. error="'.
		                     $self->{zconf}->{error}.'", errorString="'.
		                     $self->{zconf}->{errorString}.'"';
		warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString});
		return $self;
	}

	return 1;
}

#blanks the error flags
sub errorblank{
	my $self=$_[0];

	if ($self->{perror}) {
		warn('ZConf-DevTemplate errorblank: A permanent error is set');
		return undef;
	}

	$self->{error}=undef;
	$self->{errorString}="";
	
	return 1;
}

1; # End of ZConf::DBI