#!/usr/bin/env perl

use strict;

# Only needed to find modules in the dist archive.
use FindBin qw($Bin);
use File::Spec;
use lib File::Spec->catfile($Bin,'..','lib');

# actual example code

use Config::Param;

my $a2ops = 0;
my $h2ops = 0;

sub even_check
{
	return ($_[2] % 2) != 0;
}

my $p = Config::Param::get
(
	{
		 version=>'0.0.1'
		#,verbose=>1
		,info=> <<EOT
just a quick hack to demonstrate Config::Param validation

This should complain early if you fail to provide values, and valid ones
at that.
EOT
	},[
		{ long=>'scalar1', short=>'s', value=>0, help=>'a number'
		,	regex=> qr/^\d+$/, flags=>$Config::Param::nonempty }
	,	{ long=>'array1', short=>'a', value=>[], help=>'an array of non-numeric text bits'
		,	regex=> qr/^\D+$/, flags=>$Config::Param::nonempty }
	,	{ long=>'hash1', value=>{}, help=>'a hash with textual values, only signle words allowed'
		,	regex=> qr/^\w+$/, flags=>$Config::Param::nonempty }
	,	{ long=>'scalar2', short=>'S', value=>0, help=>'an even number'
		,	call=>\&even_check }
	,	{ long=>'array2', short=>'A', value=>[], help=>'an array of non-numeric text bits'
		,	regex=> qr/^\D+$/, call=>sub { ++$a2ops unless defined $_[3]; return 0}
		,	flags=>$Config::Param::nonempty }
	,	{ long=>'hash2', value=>{}, help=>'a hash with textual values, only single words allowed'
		,	regex=> qr/^\w+$/, call=>sub { ++$h2ops unless defined $_[3]; return 0}
		,	flags=>$Config::Param::append
		}
	]
);

print "I could have done some work. Command-line ops on array2: $a2ops, on hash2: $h2ops\n";
