BoutrosLab::TSVStream:IO::Role::Reader::Dyn
$class->reader( ... ); # ($class will use the role BoutrosLab::TSVStream which will provide # the reader method, that method will return a Reader object with: # ... # return BoutrosLab::TSVStream::Reader->new( # handle => $fd, # (required) # class => $class, # (required) class # file => $file, # (optional) used (as filename) in error messages # header => $str, # (optional) one of: check none (default 'check') # ); while (my $record = $reader->read) { # ... $record is a $class object # ... use $record->field1, $record->field2, etc. - all of the methods of $class object }
This object provides an iterator to read through the lines of a data stream ($fd), converting each from a line with tab separated fields into an object of a class ($classs) that has attributes for those fields.
$fd
$classs
Usually, the data stream will start with a line that has the fieldnames in a tab separated list, and the rest of the stream has lines that contain the field values in a tab separated list.
Any error diagnostics will refer to the stream using the $file filename if it is provided.
$file
The $class class will have a class attribute named _fields. Usually, this will be a read-only method that returns a list of fieldnames that will be used to validate the first line in the data stream (which should contain the field names as the column vlues).
$class
_fields
A class $class object will be created for each line. The object will be initialized with a list of names and values matching the fields and the contents .of the line.
If header is provided, it can be 'check', or 'none'. This controls what is done to the handle initially.
header
If 'check' is specified, the first line of the stream is read and it is checked to ensure that it matches the fields both in name and order. The fields list must be complete. However, it is permitted for the field names to mismatch by having different capitalization - the comparison is not case sensitive.
fields
If 'none' is specified, the stream is not checked for a header line. (You would use this option either if the file does not have a header line, or if you are scanning from the middle of a file handle that is no longer at the start of the file.)
handle, file, class and fields are provided by the ...::Base role
The 'check' setting causes the first line of the stream to be read and validated against the fields list. The field names are accepted if they match (but differences in upper/lower case are ignored). If they do not match, an exception is thrown.
'check'
If the 'none' setting is provided, the stream should already be positioned at a data value (i.e. the stream was previously opened and is no longer positioned at the start, or else the stream was originally created without a leading header line).
'none'
The default 'auto' setting causes the first line to be read and validated as for the 'check' setting, but if the line does not match the list of fields it is assumed to instead be the first data line of a stream that has no headers, and processing continues as if the 'none' setting were specified instead.
'auto'
The BUILDARGS opens a handle if only a file name was provided.
The BUILD method handles any requirements for reading and processing a header line.
John Macdonald - Boutros Lab
Paul Boutros, Phd, PI - Boutros Lab
The Ontario Institute for Cancer Research
To install BoutrosLab::TSVStream, copy and paste the appropriate command in to your terminal.
cpanm
cpanm BoutrosLab::TSVStream
CPAN shell
perl -MCPAN -e shell install BoutrosLab::TSVStream
For more information on module installation, please visit the detailed CPAN module installation guide.