1 package CXGN
::Tools
::Parse
;
4 =head1 CXGN::Tools::Parse
6 Interface-like base class for CXGN parsers.
8 Two different methods are encouraged:
9 1) Give a filename to new(), and a filehandle is created,
10 and you can parse one entry at a time w/ next().
11 2) Send raw data to new(), and automatically parses everything
12 at once with parse_all(), pushing each entry, as a hash ref,
13 to @{$self->{entries}}
17 C. Carpita <csc32@cornell.edu>
25 Args: (opt) raw output data
27 Side: Calls parse() automatically if argument provided
33 my $self = bless {}, $class;
34 my $data_or_file = shift;
36 $self->{file
} = $data_or_file;
38 open($fh, $self->{file
}) or die "Can't open file for reading: " . $self->{file
} . "\n";
42 $self->{data
} = $data_or_file;
43 $self->{data_to_parse
} = $data_or_file;
44 $self->parse_all_data();
51 while(my $entry = $self->next()){
52 push(@
{$self->{entries
}}, $entry);
53 $self->{entry_by_id
}->{$entry->{id
}} = $entry;
60 return $self->{entry_by_id
}->{$id};
65 return @
{$self->{entries
}};
72 #my $data = $self->{data_to_parse};
73 # grab entry, set hash, then...
74 # $self->{data_to_parse} = $data_with_stuff_chopped_off
77 #or this, if filehandle exists:
79 #my $fh = $self->{fh};
80 # do filehandle reads, grab entry, set hash
84 die "Override this function in a subclass";
91 $self->{fh
}->close() if $self->{fh
};