NAME

Chooser - A system for choosing a value for something. Takes a string composed of various tests, arguements, and etc and returns a value based on it.

VERSION

Version 2.0.0

SYNOPSIS

Takes a string composed of various tests, arguements, and etc and returns a value based on it. See FORMATTING for more information on the string.

    use Chooser;

	#The first tests if /test/ matches the hostname. If it does
	# a value of test is set with a wieght of 42. This makes 
	#it heavier so even if another is matched, this will be returned.
	#
	#The second test checks to make sure that no interfaces have a
	#CIDR of 192.168.0.0/16. If it does a value of not192168 is returned. 
	#
	#The third tests if
	my $string="hostregex|1|test|42|regex=test\n".
				"cidr|0|not192168|1|cidr=192.168.0.0/16".
				"defgateway|0|19216801|1|ip=192.168.0.1"

    my ($success, $choosen) = choose($string);
    if(!$success){
    	print "The choosen value is '".$choosen."'\n";
    }else{
    	print "Chooser hit a error processing...\n".$string."\n";
    };
    ...

EXPORT

chooose

FUNCTIONS

choose

This function is used for running a chooser string. See FORMATING for information on the string passed to it.

If any of the lines in the string contain errors, choose returns a error.

There are three returned values. The first return is a bolean for if it succedded or not. The second is the choosen value. The third is the wieght of the returned value.

FORMATTING

    $variable=data
	<check>|<expect>|<value>|<wieght>|<arg0>=<argValue0>|<arg1>=<argValue1>...

'|' is used a delimiter and there is no whitespace.

For information on the support checks, see the CHECK sections.

The expect section is the expected turn value for a check. Unless stated other wise it is going to be '0' for false and '1' for true.

The value is the return value for if it is true. The eventual returned one is choosen by the wieght. The highest number takes presdence. If equal, the last value is used.

The wieght is the way for the returned value.

The args are every thing after the wieght. Any thing before the first '=' is considered part of the variable name. The variable name is case sensitive. Everything after the first '=' is considered part of the value of the variable.

Both the values and arg values support templating. Templating is done via Text::NeatTemplate.

In regards to a choosen value matching /\%eval\{.*\}/, '%eval{' is removed as well as the trailing '}' and it is evaled. So for example '%eval{return "44";}' would set the value to '44'.

Any line that starts with a '$' is a variable. These can be included in stuff via the template system.

CHECKS

cidr

This checks if a specific interface or any of them have a address that matches a given CIDR.

args

cidr

The arguement "cidr" is CIDR to be matched.

if

The arguement "if" is optional arguement for the interface.

defgateway

This checks the routing table for the default route and compares it to passed variable.

args

ip

The arguement "ip" is used for the default gateway.

eval

This runs some perl code. This requires two things being returned. The first thing that needs returned is success of check. This is if the if there as a error or not with the check. It needs to return true or the choose function returns with an error condition. The second returned value is the value that is checked against expect value.

args

eval

The arguement "eval" is the arguement that contains the code used for this.

hostregex

This runs a regex over the hostname and turns true if it matches.

args

regex

The arguement "regex" is the regex to use.

netidentflag

This tests to see if a flag created by netident is present. The directory used is the default netident flag directory, unless the enviromental variable 'NETIDENTFLAGDIR' is set.

The arguement "flag" is used to specify the flag to look for.

pingmac

This test pings a IP to make sure it is in the ARP table and then checks to see if the MAC maches.

args

ip

The IP to ping

mac

The MAC to check for.

sslcert

args

To get the values to for the subject and issure, use the code below and use everything after /\: /.

use IO::Socket::SSL;
my $client->new($host.':'.$port);
print $client->dump_peer_certificate;

The required values are listed below.

host
port
subject

For more information about most of these options, please see the documentation for IO::Socket::SSL for the new method.

CAfile

The CA file to use.

CApath

CA path to use.

check_crl

Check to see if it has been revoked.

cipher_list

The cipher list to use.

crl_file

The CRL file to use.

host

This is either the hostname or IP address to connect to.

port

This is the port to connect to.

subject

This is the subject name to check for. To get what this should be, run the code below.

verify_mode

The verify mode to use.

verifycn_name

The name to use to verify the hostname.

verifycn_scheme

The scheme to use when verifying the hostname.

version

The SSL version to use.

TEMPLATING

Templating for choosen values and arg values is done using Text::NeatTemplate.

TEMPLATE KEYS

{$ENV*}

All enviromental variables have 'ENV' appended to them in the hash ref that is passed to Text::NeatTemplate.

{$hostname}

This is the hostname of the machine it is running on.

{$newline}

This inserts a "\n".

{$returned}

This is the returned value of a check. This is only present if a value is being processed.

{$pipe}

This inserts a '|'.

{$value}

This is the raw value string. This is only present if a value is being processed.

{$VAR*}

This adds in any variables.

AUTHOR

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

BUGS

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

SUPPORT

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

perldoc Chooser

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2009 Zane C. Bowers, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.