Astro-STSDAS-Table

 view release on metacpan or  search on metacpan

Table/Base.pm  view on Meta::CPAN

{ 
  my $this = shift;
  my $class = ref($this) || $this;

  my $self = {
	     # the filehandle to the table
	     fh	=> undef,
	     
	     pars => Astro::STSDAS::Table::HeaderPars->new(),
	     
	     cols => Astro::STSDAS::Table::Columns->new(),

	     nrows => undef,

	     file => undef,

	     mode => undef,

	     fh => undef

	    };


  bless $self, $class;
}

sub open
{
  @_ >=2 or croak 'usage : $self->open( $file [, $mode] )';
  my ( $self, $file, $mode ) = @_;

  $mode = '<' if ! defined $mode;
  $self->{mode} = $mode;
  my $fh = new IO::File;

  if ( ref($file) )
  {
    $fh->fdopen( $file, $mode ) || return undef;
  }
  else
  {
    $fh->open( $file, $mode ) || return undef;
  }

  $self->{file} = $file;
  $self->{fh} = $fh;

  # if this is open for reading, suck in the header
  if ( $mode =~ /[<+]/ )
  {
    $self->_read_hdr;
  }

  1;
}

sub METHOD::ABSTRACT
{
  my ($self) = @_;
  my $object_class = ref($self);
  my ($file, $line, $method) = (caller(1))[1..3];
  my $loc = "at $file, line $line\n";
  die "call to abstract method ${method} $loc";
}


sub _read_hdr { ABSTRACT METHOD @_ }
sub read_cols { ABSTRACT METHOD }
sub read_rows { ABSTRACT METHOD }

sub close
{
  my $self = shift;

  if ( defined $self->{fh} )
  {
    close $self->{fh};
    $self->{fh} = undef;
  }
}


1;

__END__

=pod

=head1 NAME

Astro::STSDAS::Table::Base - Base class for STSDAS Tables

=head1 SYNOPSIS

  use Astro::STSDAS::Table::Base;

  @isa = qw( Astro::STSDAS::Table::Base );

  sub new
  { 
    my $this = shift;
    my $class = ref($this) || $this;

    my $self = $class->SUPER::new();

    ...

    bless $self, $class;
  }

=head1 DESCRIPTION

B<Astro::STSDAS::Table::Base> is a base class and should be sub-classed
to derive any functionality.  B<Astro::STSDAS::Table::Binary> is a
fully derived class which reads binary STSDAS tables.

B<Astro::STSDAS::Table::Base> provides several methods and requires
that the derived class provide the rest.

The base class constructor (which must be called by the derived class)
creates a hash object.  The following keys are reserved, and shouldn't



( run in 1.314 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )