Config-ReadAndCheck

 view release on metacpan or  search on metacpan

ReadAndCheck.pm  view on Meta::CPAN


		$NewParams->{$Name}->{'Type'} = $Params->{$Name}->{'Type'}
			or $NewParams->{$Name}->{'Type'} = 'UNIQ';
		$NewParams->{$Name}->{'Type'} = uc($NewParams->{$Name}->{'Type'});

		if (!(($NewParams->{$Name}->{'Type'} eq 'UNIQ')     ||
		      ($NewParams->{$Name}->{'Type'} eq 'LIST')     ||
		      ($NewParams->{$Name}->{'Type'} eq 'UNIQLIST') ||
		      ($NewParams->{$Name}->{'Type'} eq 'IGNORE')))
			{
			$@ = "$Path\->$Name\->{'Type'} have to be 'UNIQ', or 'LIST', or 'UNIQLIST', or 'IGNORE'!";
			#if($^W) { Carp::carp $@; };
			return;
			};

		$NewParams->{$Name}->{'Process'} = $Params->{$Name}->{'Process'}
			or $NewParams->{$Name}->{'Process'} = $SimpleProcess;

		if (ref($NewParams->{$Name}->{'Process'}) ne 'CODE')
			{
			$@ = "$Path\->$Name\->{'Process'} have to be a 'CODE' reference!";
			#if($^W) { Carp::carp $@; };
			return;
			};

		(!exists($Params->{$Name}->{'Default'}))
			or $NewParams->{$Name}->{'Default'} = $Params->{$Name}->{'Default'};

		defined($Params->{$Name}->{'SubSection'})
			or next;

		if (ref($Params->{$Name}->{'SubSection'}) ne 'HASH')
			{
			$@ = "$Path\->$Name\->{'SubSection'} have to be reference to 'HASH'!";
			#if($^W) { Carp::carp $@; };
			return;
			};

		$NewParams->{$Name}->{'SubSection'} = &{$CheckParams}($Params->{$Name}->{'SubSection'}, "$Path\->$Name")
			or return;
		};
	return $NewParams;
	};

sub new($%)
	{
	my ($class, %Config) = @_;

	(!&{$CheckLoop}($Config{'Params'}))
		or return;

	my $self = {};

	$self->{'CaseSens'} = $Config{'CaseSens'};

	$self->{'Params'} = &{$CheckParams}($Config{'Params'})
		or return;

	Reset($self);

	return bless $self => $class;
	};

sub Result($)
	{
	my ($self) = @_;
	my %Result = ();
	tie(%Result, 'Tie::IxHash', %{$self->{'Result'}});
	return (wantarray ? %Result : \%Result);
	};

sub Reset($)
	{
	my ($self) = @_;
        tie(%{$self->{'Result'}}, 'Tie::IxHash');
	$self->{'SecStack'} = [];
	unshift(@{$self->{'SecStack'}}, {'Params' => $self->{'Params'},'Result' => $self->{'Result'}});
	};

sub Params($)
	{
	my ($self) = @_;
	my $Params = &{$CheckParams}($self->{'Params'});
	return (wantarray ? %{$Params} : $Params);
	};

my $ParseLine = sub($$)
	{
	my ($self, $Str, $Params) = @_;

	my $Name = undef;

	#print "###########################\n".PrintList($Params, 'p: ', '  ');

	foreach $Name (keys(%{$Params}))
		{
		my $Pattern = $Params->{$Name}->{'Pattern'};

		my ($P1, $P2);
		($self->{'CaseSens'} ? $Str =~ m/\A$Pattern\Z/ : $Str =~ m/\A$Pattern\Z/i)
			or next;
		$@ = '';
		if (!(($P1, $P2) = &{$Params->{$Name}->{'Process'}}()))
			{
			length($@)
				or $@ = "Invalid value(s) in '$Name' definition";
			#if($^W) { Carp::carp $@; };
			return;
			};
		return ($Name, $P1, $P2);
		};

	$@ = "Unrecognized string";
	#if($^W) { Carp::carp $@; };
	return;
	};

my $CheckRequired = undef;
$CheckRequired = sub
	{
	my ($Params, $Result, $Path) = @_;

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.437 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )