################################################################## 
## Class Name: DefaultOutputController                          ##
##                                                              ##
## Description: This class is the default concrete controller   ##
##              class that is instantiated and returned by the  ##
##              default output controller factory               ##
##                                                              ##
## Arguments: None.                                             ##
##                                                              ##
##################################################################
package APE::OutputControllerFactory::ConcreteOutputController::DefaultOutputController;

use base 'APE::OutputControllerFactory::ConcreteOutputController::OutputController';

$APE::OutputControllerFactory::ConcreteOutputController::DefaultOutputController::VERSION = '0.6';

use strict;
use warnings;
use Carp;

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

{
    my %_attributes = ();

    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} }
    }


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

	## Set attributes to passed values if present.
	foreach my $attName (keys(%args)) {
	    if(exists($_attributes{$attName})) {
		$object{ $self }->{$attName} = delete $args{$attName};
	    }
	}

	## Push the default options so that they are advertised for
	## use by the class user as output methods.
	$self->pushOption('Show STDOUT' => \&_showStdout);

	return $self->SUPER::_init(%args);
    }

    
    #################################################################
    ## @@DEBUG debug method to print the contents of a Result object to
    ## STDOUT.
    #################################################################
    sub _showStdout {
	my ($self,$results) = @_;
	foreach my $result (@{$results}) {
            my $description = $result->getDescription;
            print STDOUT "*** SUMMARY OF RESULT ***\n";
	    print STDOUT "SessionId  : ",$result->getSessionId,"\n";
	    print STDOUT "Id         : ",$result->getId,"\n";
	    print STDOUT "Type       : ",$result->getType,"\n";
	    print STDOUT "Format     : ",$result->getFormat,"\n";
	    foreach my $key (keys %$description) {
		warn "Description: $key -> $description->{$key}\n";
	    }
	}
    }
}


1;
