package Reader::Reader;


#
# we are serving as an "abstract" root class

sub new {
    die "cannot instanciate Reader::Reader";
}


#
# create a reader when its name is determined dynamically
# at runtime

sub create {
    my( $name, $args ) = @_;

    my $reader;
    eval {
	require "Reader/$name.pm";
	$reader = eval "new Reader::$name";
    };
    die "Reader $name is unknown" unless( $reader );
    $reader->set_arguments( $args );
    $reader->set_name( $name );
    return $reader;
}



#
# set arguments for this reader.
# The argument is expected to be a hash reference with
#    "start"=>start time
#    "end" => end time
#    "args" => an array reference pointing to some command line args

sub set_arguments() {
    my( $self, $args ) = @_;

    $self->{"arguments"} = $args;
}


#
# get an argument as set by set_arguments

sub get_argument() {
    my( $self, $argname ) = @_;

    return( undef ) unless( $self->{"arguments"} );
    return( $self->{"arguments"}->{$argname} );
}


#
# set the name of this reader

sub set_name {
    my( $self, $name ) = @_;

    $self->{"name"} = $name;
}


#
# get the name of this reader

sub get_name {
    my( $self ) = @_;
    return( $self->{"name"} );
}


#
# read whatever this reader is meant to read and return
# a StatusLog object

sub read {
    die "this reader (".($self->get_name()).") does not support reading";
}


#
# dump a StatusLog object to wherever this reader is meant
# to write to

sub dump {
    die "this reader (".($self->get_name()).") does not support dumping";
}

1;
