package Yaa::LookupMap::Driver::STATIC;

# inherit everything from Yaa::LookupMap
@ISA = qw(Yaa::LookupMap);

use strict;
use vars qw ($VERSION);

=head1 NAME

Yaa::LookupMap::Driver::STATIC - static lookup map driver

This driver never performs any kind of lookups to any backend.

It always return Yaa::LookupMap::Result object with predefined results. See setParams() method.

=cut

=head1 SYNOPSIS

my $static_map = Yaa::LookupMap->factory(

	driver => 'STATIC',
	result => 'this is result value',
	something => 'this is really something'

);

my $result = $static_map->lookup("anything");

my $sth = $static_map->lookup("anything");

# prints 'this is result value'
print $result->getMatchValueByKey('result');

# prints 'this is really something'
print $sth->getMatchValueByKey('something');

=cut

######################################################
#                GLOBAL VARIABLES                    #
######################################################
my $VERSION = "0.1";

######################################################
#               OBJECT CONSTRUCTOR                   #
######################################################

=head1 OBJECT CONSTRUCTOR

Object constructor accepts any parameters in key => value grammatic.

key becomes lookup result key, and value becomes lookup result key value.

=cut
sub new {
	my $proto = shift;
	my $class = ref($proto) || $proto;
	my $self = Yaa::LookupMap->new();

	##################################################
	#               PUBLIC VARS                      #
	##################################################

	# results hash
	$self->{results} = undef;


	##################################################
	#              PRIVATE VARS                      #
	##################################################

	bless($self, $class);
	
	# clear parameters
	$self->clearParams();

	# set object properties	
	$self->setParams(@_);

	return $self;
}

=head1 METHODS

=cut

=head2 setParams (result_name1 => result_value1)

Sets lookup result parameters.

=cut
sub setParams {
	my ($self) = shift;
	
	while (defined (my $name = shift) && defined (my $value = shift)) {
		$self->{results}->{$name} = $value if (substr($name, 0, 1) ne '_' && $name ne 'driver');
	}
	
	return 1;
}


=head2 clearParams () 

Clears object parameters.

=cut
sub clearParams {
	my ($self) = @_;
	$self->{results} = undef;
}

####################################################
#               PRIVATE METHODS                    #
####################################################

# performs actual lookup
sub _lookup {
	my ($self) = @_;
	my $result = Yaa::LookupMap::Result->new();
	$result->addMatch($self->{results});
	return $result;
}

1;

=head1 SEE ALSO

For general class usage, please see perldoc Yaa::LookupMap.

=cut

=head1 AUTHOR

Branko F. Gracnar <bfg@frost.ath.cx>
http://frost.ath.cx/~bfg

=cut

=head1 LICENSE

This software is released under BSD-style license. If you like this software, send me a nice postcard from somewhere to the snail mail address published on my website.

=cut

