The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

BaMo::Role::FileIO - File input & ouput interface for parser classes

SYNOPSIS

    use Mouse;

    with 'BaMo::Role::FileIO';

    sub parse {
        my ($self) = @_;
        $fhi = $self->_fhi;

        while(my $line = $fhi->()) {
            #parse a bit
            if($line =~ /break/) {
                # oh no, we parsed too much...
                push @{$self->_cached_records}, $line;
                #but we can reverse it
            }
        }
    }

DESCRIPTION

Enhances the class that uses this role with a file handle iterator that is capable of caching records (lines in most cases), in case you read too much.

METHODS

$self->fh()

Get or set the filehandle.

$self->_cached_records()

You can push lines on @{$self->_cached_records} (they need to be chomped already). The file handle iterator will use them first if you call it. The file handle will not be touched until all cached lines are shifted.

$class->new(file => 'filename.xyz', mode => '<')

Opens the file in the specified mode. Sets the fh and _fhi attribute (indirectly).

$self->_fhi()

Get the file handle iterator.

$class->new(fh => $fh)
$self->close()

Close the filehandle.

SEE ALSO

AUTHOR

jw bargsten, <joachim.bargsten at wur.nl>