Options

1.1

Introduction

Options is a class giving you the ability to easily parse optionfiles in your perl programms.
With Options you can implement a hierarchical option structure which this class can parse into a single anon perl hash structure or you can extrace single options.
To implement a hierarchic structure you must seperate options attributes using a ".".
The main syntax of an optionline is:
attribute[.attribute[..]] = value

Blank lines or lines starting with a # (hash-sign) will be ignored during parsing.

Lets construct an example optionfile for configuring cars and their attributes.
We call our optionfile "cars.properties" and it looks like this:

  audi.tt.doors = 2
  audi.tt.ps = 250
  audi.a4.doors = 4
  audi.a4.ps = 130
  porsche.cayenne.doors = 4
  porsche.boxter.doors = 2

Now you got two options.

Lets consider you want to parse a single value: audi.a4.ps
  my $psAudiA4 = $caropts->getProperty("audi.a4.ps");
$psAudiA4 will now hold the value "130".

Lets consider you want to parse the whole option file.
  my $caroptsStruct = $caropts->getCompleteConfig();
No $caroptsStruct will have the following layout:
  $caroptsStruct->{audi}->{tt}->{doors} = 2
  $caroptsStruct->{audi}->{tt}->{ps} = 250
  $caroptsStruct->{audi}->{a4}->{doors} = 4
  $caroptsStruct->{audi}->{a4}->{ps} = 130
  $caroptsStruct->{porsche}->{cayenne}->{doors} = 4
  $caroptsStruct->{porsche}->{boxter}->{doors} = 2

Author

Markus Mazurczak <coding@markus-mazurczak.de>

Bugtracking

If you find any bugs or want to have a particular feature included register at http://mantis.markus-mazurczak.de

Dependencies

Installation

Download and unpack Options into a directory your perl programm can access and also put Merror.pm into the same directory as Options.pm

Error handling

Options uses the Merror class to implement error handling with a stacktrace function. The Merror object will be accessible through the MERROR member of the Options object.
E.g.: $opts->{MERROR}->error();

Example

Lets create the following directory structure: $HOME/src/test

Now lets assume that we got no read permissions on cars.properties
than the output will look like the following:

Error code: -1
Error description: Could not read option file: /home/nexus/src/perl/test/properties/cars.properties
Stacktrace:
Level: 0 -- File: /home/nexus/src/perl/test/lib/Merror.pm -- Pkg: Merror -- Sub: Merror::fillstack -- Line: 131
Level: 1 -- File: /home/nexus/src/perl/test/lib/Options.pm -- Pkg: Options -- Sub: Merror::error -- Line: 208
Level: 2 -- File: /home/nexus/src/perl/test/lib/Options.pm -- Pkg: Options -- Sub: Options::checkOptfile -- Line: 100
Level: 3 -- File: ./test.pl -- Pkg: main -- Sub: Options::new -- Line: 17

Generated on Tue Feb 16 00:54:58 2010 for Options by  doxygen 1.5.8