File Coverage

blib/lib/Astro/STSDAS/Table/Base.pm
Criterion Covered Total %
statement 25 50 50.0
branch 0 14 0.0
condition 1 3 33.3
subroutine 8 14 57.1
pod 3 5 60.0
total 37 86 43.0


line stmt bran cond sub pod time code
1             package Astro::STSDAS::Table::Base;
2              
3             our $VERSION = '0.12';
4              
5 2     2   31270 use strict;
  2         6  
  2         83  
6 2     2   11 use Config;
  2         5  
  2         80  
7 2     2   2112 use POSIX;
  2         13585  
  2         12  
8              
9              
10 2     2   9440 use IO::File;
  2         11957  
  2         633  
11 2     2   16 use Carp qw( carp croak );
  2         3  
  2         106  
12              
13 2     2   1427 use Astro::STSDAS::Table::HeaderPars;
  2         15  
  2         60  
14 2     2   1194 use Astro::STSDAS::Table::Columns;
  2         6  
  2         1099  
15              
16             sub new
17             {
18 1     1 1 15 my $this = shift;
19 1   33     8 my $class = ref($this) || $this;
20              
21 1         11 my $self = {
22             # the filehandle to the table
23             fh => undef,
24            
25             pars => Astro::STSDAS::Table::HeaderPars->new(),
26            
27             cols => Astro::STSDAS::Table::Columns->new(),
28              
29             nrows => undef,
30              
31             file => undef,
32              
33             mode => undef,
34              
35             fh => undef
36              
37             };
38              
39              
40 1         5 bless $self, $class;
41             }
42              
43             sub open
44             {
45 0 0   0 1   @_ >=2 or croak 'usage : $self->open( $file [, $mode] )';
46 0           my ( $self, $file, $mode ) = @_;
47              
48 0 0         $mode = '<' if ! defined $mode;
49 0           $self->{mode} = $mode;
50 0           my $fh = new IO::File;
51              
52 0 0         if ( ref($file) )
53             {
54 0 0         $fh->fdopen( $file, $mode ) || return undef;
55             }
56             else
57             {
58 0 0         $fh->open( $file, $mode ) || return undef;
59             }
60              
61 0           $self->{file} = $file;
62 0           $self->{fh} = $fh;
63              
64             # if this is open for reading, suck in the header
65 0 0         if ( $mode =~ /[<+]/ )
66             {
67 0           $self->_read_hdr;
68             }
69              
70 0           1;
71             }
72              
73             sub METHOD::ABSTRACT
74             {
75 0     0     my ($self) = @_;
76 0           my $object_class = ref($self);
77 0           my ($file, $line, $method) = (caller(1))[1..3];
78 0           my $loc = "at $file, line $line\n";
79 0           die "call to abstract method ${method} $loc";
80             }
81              
82              
83 0     0     sub _read_hdr { ABSTRACT METHOD @_ }
84 0     0 0   sub read_cols { ABSTRACT METHOD }
85 0     0 0   sub read_rows { ABSTRACT METHOD }
86              
87             sub close
88             {
89 0     0 1   my $self = shift;
90              
91 0 0         if ( defined $self->{fh} )
92             {
93 0           close $self->{fh};
94 0           $self->{fh} = undef;
95             }
96             }
97              
98              
99             1;
100              
101             __END__