PrePAN

Sign in to PrePAN

File::Parser::Role A small but convenient framework for parsing files

Author
torbjorn@github
Date
URL
Status
In Review
Good

Synopsis

package SupaParser;

use Moo;

sub parse {

  my $self = shift;

  work_magic( $self->fh );

}

with "File::Parser::Role";

1;

Description

A role that accepts a single filename or a normal hash[ref] to constructor with a file argument

It requires and runs $self->parse after construction.

It provides a fh method that gives a file handle seek'ed to 0 (when it's seekable), which is nice to have in sub parse.

And:

  • if given a local file resource: checks that the file exists and is readable
  • also accepts a file handle
  • also accepts a scalar ref to some content to be parsed
  • accepts url's

In short - all those boring tedious things that you have to re-do every time you want to parse a file.

With this shiny role you can skip all that and get straight to the fun bit: The parsing.

Comments

Please sign up to post a review.