###################################################################

package KoLBot::StateManager;
 
# Copyright (c) 2004 Alan W. Mahoney. All rights reserved. 
# This program is free software.  You may modify and/or 
# distribute it under the same terms as Perl itself.  
# This copyright notice must remain attached to the file.  
#
# Forms a base class for an in-memory state manager.  Eventually
# there should be versions of this for relational DB or flat-file
# interfaces

use warnings;
use strict;

BEGIN 
{
  use Exporter ();
  our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $ID);

  $VERSION     = 0.5;
  $ID          = '$Id';

  @ISA         = qw(Exporter);
  @EXPORT      = qw();
  %EXPORT_TAGS = ( );

  @EXPORT_OK   = qw();
}

our @EXPORT_OK;

##########################################
## element access
##########################################

for my $field (qw( 
		   config
		   )) {
  no strict "refs";
  *$field = sub {
    my $self = shift;
    $self->{$field} = shift if @_;
    return $self->{$field};
  }
}

##########################################
## Constructor:
##########################################

sub new {
  my $invocant = shift;
  my $class = ref($invocant) || $invocant;
  my $limiter = { 
		  @_ };
  bless $limiter, $class;
}

##########################################
## The rest
##########################################

sub set {
  my $sm = shift;
  my $name = lc(shift);
  my $property = shift;
  my $value = shift;

  exists($sm->{$name}) or $sm->{$name} = {};
  $sm->{$name}->{$property} = $value;
}

sub get {
  my $sm = shift;
  my $name = shift;
  my $property = shift;

  exists($sm->{$name}) or return {};
  return $sm->{$name}->{$property};
}
  

END {} ;

1;

