package APE::FlushController::Result;

use strict;
use warnings;
use Carp;

use constant TRUE  => 1;
use constant FALSE => 0;


{
    my %_attributes = (
		       sessionId       => undef,
		       id              => undef,
		       type            => undef,
		       description     => {},
		       'format'        => undef,
		       report          => undef,
		       reportRaw       => [],
		       flushController => undef,
		       );
    
    my %object; 
 
        
    ## Autoloader wannabe. Inserts the sub calls that I want to be
    ## accessible into the symbol table.
    foreach my $attName (keys(%_attributes)) {
	no strict 'refs';
	*{__PACKAGE__ . "::get\u$attName"} = sub { $object{ $_[0] }->{$attName} }
    }


    #################################################################
    ## Constructor method for this object. Returns a new
    ## Result object.
    #################################################################
    sub new {
	no strict 'refs';
	my ($proto,%args) = @_;
	
	my $class = ref($proto) || $proto;
	my $self = bless {}, $class;
	
	%args = $self->_init(%args);

	my @leftover = keys %args;

	confess "Error: @leftover" if @leftover;

	return $self;
    }


    #################################################################
    ## Initialise the objects private attributes. The argument is
    ## deleted as it is found, initialised and set.
    #################################################################
    sub _init {
	my ($self,%args) = @_;

	foreach my $attName (keys(%args)) {
	    if(exists($_attributes{$attName})) {
		$object{ $self }->{$attName} = delete $args{$attName};
	    }
	}
	return %args;
    }


    #################################################################
    ## Method to destroy this object.
    #################################################################
    sub DESTROY {
	my $self = shift;
	delete $object{ $self };
    }
}

1;
