GetRc






Pair Networks
GetRc

NAME

GetRc - A Module for reading configuration files

SYNOPSIS

  use GetRc;

  my $file = GetRc->new ("file_name");
  $file->ifs('\s*:\s*');
  my $result_get = $file->getrc(\%input);

  my $newfile = GetRc->new ("new_file_name");
  $newfile->ofs(' = ');
  my $result_wri = $newfile->writerc(\%input);

  my $updatefile = GetRc->new ("update_file_name");
  $updatefile->ifs('\s*:\s*');
  $updatefile->ofs(' = ');
  my $result_upd = $upadtefile->updaterc(\%input);

DESCRIPTION

This perl library provides reading, writing and updating configuration files which is outside your Perl script.

The current version of GetRc.pm is available at

  http://rodney.alert.sk/perl/

INSTALLATION

To install this package, just change to the directory in which this file is found and type the following:

	perl Makefile.PL
	make
	make test
	make install

This will copy GetRc.pm to your perl library directory for use by all perl scripts. You probably must be root to do this. Now you can load the GetRc routines in your Perl scripts with the line:

	use GetRc;

VERSION

  0.23

USE

Functions ( or Methods ? )

new
	$file = GetRc->new($filename);

This creates a new GetRC object, using $filename, where $filename specified (may be relative) path to filename.

For 'filename' looking in directories defined in $file->find_path. Default find_path contain:

    ### actual directory
    "./",
    ### home directory
    (getpwuid($>))[7]."/",
    ### program directory by File::Basename::fileparse()
    $dirname,
    ### parent directory
    "../",
    ### default config directory
    "/usr/local/etc/"

You may redefine find_path with push, pop, shift and unshift methods.

getrc
	$retval = $file->getrc(\%input);
	

Fetch file content to %input.

writerc
	$retval = $file->writerc(\%input);

Write %input to 'filename' each entry per line.

updaterc
	$file = GetRc->new("filename");
	$retval = $file->updaterc(\%input);

Update specified file with %input. Get configuration fields from "filename", update by %input and write to "filename".

ifs
	$file->ifs($ifs);

Definition Input Fields Separator. Default is used '\s*=\s*'. You may use regex in this piece.

ofs
	$file->ofs($ofs);

Definition Output Fields Separator. Default is used ' = '. Don't use regex.

Other functions
	$file->configure (
		ifs => '\s*=\s*',
		ofs => ' : ',
		debug => 1,
		find_path => $array_ref,
		....
	);

	$file->find_path->push("value");
	$file->find_path->pop();
	$file->find_path->unshift("value");
	$file->find_path->shift();
	my @PATH = $file->find_path();

Return codes

Return codes from getrc,writerc,updaterc:

   0  =  if everything is O.K
  -1  =  if 'filename' doesn't exist
  -2  =  if can't read 'filename'
  -3  =  if file lock timeouted
  -4  =  if can't open file for writing

Return codes from other functions ( methods ? ) is value

EXAMPLE

#!/usr/bin/perl

use GetRc;

$file = GetRc->new (".pinerc"); $file->configure( ifs => '\s*=\s*', );

$file->getrc(\%input);

foreach ( keys %input ) { print "$_ -> $input{$_}\n"; }

DEBUG

	If $object->debug is set then print some debug informations on STDERR 
	$object->debug(1); ## default is 0 - no debug info

AUTHOR INFORMATION

Copyright 1997-2000 Jan 'Kozo' Vajda <Jan.Vajda@alert.sk>. All rights reserved. It may be used and modified freely, but I do request that this copyright notice remain attached to the file. You may modify this module as you wish, but if you redistribute a modified version, please attach a note listing the modifications you have made.

Address bug reports and comments to: Jan.Vajda@alert.sk

CREDITS

Thanks very much to:

my wife Erika
for patience
mico ( mico@pobox.sk )
for inspiration
koleso ( tibor@pobox.sk )
for permanent discontent
milo ( milo@pobox.sk )
for background noise
Alert Security Group ( alert@alert.sk )
for some suggestions & solutions
O'Reilly and Associates, Inc
for my perl book :-{))
...and many many more...
for many suggestions and bug fixes.

SEE ALSO

IniConf , perl(1)