Config::Sofu - Easy interface to configuration files in .sofu format


sofu-config documentation Contained in the sofu-config distribution.

Index


Code Index:

NAME

Top

Config::Sofu - Easy interface to configuration files in .sofu format

SYNOPSIS

Top

	use vars qw/%CONFIG/; 
	use Config::Sofu "config.sofu"; 
	if ($CONFIG{FOOBAR}) {
		...
	}
	if ($CONFIG{Bar}->[7]->{Foo} eq "Foobar") {
		...
	}

Save the new configuration:

	$CONFIG{FOOBAR}="Bar times Foo";
	Config::Sofu::save;

or

	Config::Sofu::save(%CompletlyNewConfig)

SYNTAX

Top

This class exports the hash %CONFIG by default which contains all the information of the file given to the use statement.

DESCRIPTION

Top

This module does just one thing: It loads data from a .sofu file and puts it into %CONFIG.

FUNCTIONS AND METHODS

Top

save()

Save the new configuration of to the same file again.

If the file was binary sofu it is saved again in binary sofu.

BUGS

Top

The comments in the sofu-file will only be saved again if Data::Sofu >= 0.2.3 is installed.

Can only read binary sofu files if Data::Sofu >= 0.2.8 is installed.

SEE ALSO

Top

Data::Sofu,perl(1),http://sofu.sf.net


sofu-config documentation Contained in the sofu-config distribution.

package Config::Sofu;
use Data::Sofu;
use strict;
use warnings;
require Exporter;
use vars qw/$VERSION @EXPORT @ISA %CONFIG $file $Sofu $Comment $wasbinary/;
use Carp;

$VERSION="0.5";
@ISA = qw(Exporter);
@EXPORT=qw/%CONFIG/;
%CONFIG=();
$Sofu="";
$file="";
$Comment="";
$wasbinary="";
sub import {
	my $class=shift;
	my $file=shift;
	die "Usage: use Config::Sofu \"file\"" if ref $file or not -e $file;
	$Config::Sofu::file=$file;
	$Config::Sofu::Sofu=Data::Sofu->new;
	%Config::Sofu::CONFIG=$Config::Sofu::Sofu->read($file);
	$Config::Sofu::Comment=$Config::Sofu::Sofu->comment if $Data::Sofu::VERSION ge "0.23";
	$Config::Sofu::wasbinary=$Config::Sofu::Sofu->{BINARY} if $Config::Sofu::Sofu->{BINARY};
	Config::Sofu->export_to_level(1, '%CONFIG',@_);
}
sub save {
	my $class=shift if @_ and $_[0] eq "Config::Sofu";
	die "Arguments to save() must be empty or hash" if scalar @_ % 2;
	die "No imports. Please \"use\" this module first" unless $Sofu;
	#warn "Usage: Config::Sofu::save(%CONFIG)" and return 0 if not @_ or scalar @_ % 2;
	my %CONF=%main::CONFIG;
	%CONF=@_ if @_;
	if ($Data::Sofu::VERSION ge "0.23") {
		if ($Config::Sofu::wasbinary) {
			$Config::Sofu::Sofu->writeBinary($Config::Sofu::file,\%CONF,$Config::Sofu::Comment);
		}
		else {
			$Config::Sofu::Sofu->write($Config::Sofu::file,\%CONF,$Config::Sofu::Comment);
		}
	}
	else {
		$Config::Sofu::Sofu->write($Config::Sofu::file,\%CONF);
	}
}
1;

1;