| ZConf-DevTemplate documentation | Contained in the ZConf-DevTemplate distribution. |
ZConf::template -
Version 0.0.0
Quick summary of what the module does.
Perhaps a little code snippet.
use ZConf::template;
my $foo = ZConf::template->new();
...
This initializes it.
One arguement is taken and that is a hash.
If this is defined, it will be used instead of creating a new ZConf object.
my $foo=ZConf::template->new;
if($foo->error){
warn('error '.$foo->error.': '.$foo->errorString);
}
This removes the specified ZConf set.
$foo->delSet('someSet');
if($foo->{error}){
warn('error '.$foo->error.': '.$foo->errorString);
}
This returns the ZConf object.
The only time this will error is if a permanent error is set.
my $zconf=$foo->getZConf;
if ($foo->error){
warn('error '.$foo->error.': '.$foo->errorString);
}
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}){
warn('error '.$foo->error.': '.$foo->errorString);
}
This lists the available sets for the ZConf config.
my @sets=$foo->listSets;
if($foo->{error}){
warn('error '.$foo->error.': '.$foo->errorString);
}
This reads a specified ZConf set.
If no set is specified, the default is used.
$foo->readSet('someSet');
if($foo->{error}){
warn('error '.$foo->error.': '.$foo->errorString);
}
This returns the current error code if one is set. If undef/evaulates as false then no error is present. Other wise one is.
if($foo->error){
warn('error '.$foo->error.': '.$foo->errorString);
}
This returns the current error string. A return of "" means no error is present.
my $errorString=$foo->errorString;
This blanks the error storage and is only meant for internal usage.
It does the following.
$foo->{error}=undef;
$foo->{errorString}="";
ZConf errored.
%%%%AUTHOR%%%, <%%%EMAIL%%%>
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-template. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc ZConf::template
You can also look for information at:
Copyright 2009 %%%AUTHOR%%%, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| ZConf-DevTemplate documentation | Contained in the ZConf-DevTemplate distribution. |
package ZConf::template; use warnings; use strict; use ZConf;
our $VERSION = '0.0.0';
sub new{ my %args; if(defined($_[1])){ %args= %{$_[1]}; } my $method='new'; my $self={error=>undef, perror=>undef, errorString=>undef, zconfconfig=>'%%%ZCONFCONFIG%%%', module=>'ZConf-template', }; 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}.' '.$method.':'.$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."' exists failed. error='". $self->{zconf}->{error}."', errorString='". $self->{zconf}->{errorString}."'"; warn($self->{module}.' '.$method.':'.$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}.' '.$method.':'.$self->{error}.': '.$self->{errorString}); return $self; } #init it $self->init; if ($self->{zconf}->{error}) { $self->{perror}=1; $self->{errorString}='Init failed.'; warn($self->{module}.' '.$method.':'.$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}.' '.$method.':'.$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}.' '.$method.':'.$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."' exists failed. error='". $self->{zconf}->{error}."', errorString='". $self->{zconf}->{errorString}."'"; warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString}); return $self; } return $self; }
sub delSet{ my $self=$_[0]; my $set=$_[1]; my $method='init'; $self->errorblank; if ($self->{error}) { warn($self->{module}.' '.$method.': 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}.' '.$method.':'.$self->{error}.': '.$self->{errorString}); return $self; } return 1; }
sub getZConf{ my $self=$_[0]; my $method='getZConf'; $self->errorblank; if ($self->{error}) { warn($self->{module}.' '.$method.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"'); return undef; } return $self->{zconf}; }
sub init{ my $self=$_[0]; my $set=$_[1]; my $method='init'; $self->errorblank; if ($self->{error}) { warn($self->{module}.' '.$method.': 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}.' '.$method.':'.$self->{error}.': '.$self->{errorString}); return $self; } return 1; }
sub listSets{ my $self=$_[0]; my $method='listSets'; $self->errorblank; if ($self->{error}) { warn($self->{module}.' '.$method.': 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}.' '.$method.':'.$self->{error}.': '.$self->{errorString}); return $self; } return @sets; }
sub readSet{ my $self=$_[0]; my $set=$_[1]; my $method='readSet'; $self->errorblank; if ($self->{error}) { warn($self->{module}.' '.$method.': 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}.' '.$method.':'.$self->{error}.': '.$self->{errorString}); return $self; } return 1; }
sub error{ return $_[0]->{error}; }
sub errorString{ return $_[0]->{errorString}; }
#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::template