File::Parser::Role A simple role to make life easier when you parse files.


    package MyFileParser;

    use Moo;
    has blob => ( is => "rw" );

    sub parse {

      my $self = shift;
      my $fh = $self->fh;

      local $/;

      # just stuff it here, so not really parsing it
      $self->blob( <$fh> );


    with "File::Parser::Role";


And then in some nearby code:

    my $file_obj = MyFileParser->new( "some.file" );

    print length $file_obj->blob; # blob now has the file content because of our sub parse

    print $file_obj->size;        # size of file as reported by -s


A simple role that provides the tedious necessities when parsing files:

  • make Moo constructor work with filename as one single argument

  • if its a filename, handle it properly if it doesnt exist

  • provide a read-only file handle to the resource

  • run a required sub parse {}

  • fetch its size (its a nice thing to have)

  • accept file handles and other weirdness such as Path::Tiny, IO::All, IO::File, Mojo::Path.

  • accept references to content

All that is left is for you is the fun bit: write the code that does the parsing


To install this module, run the following commands:

        perl Makefile.PL
        make test
        make install

Alternatively, to install with Module::Build, you can use the following commands:

        perl Build.PL
        ./Build test
        ./Build install


Copyright (C) 2014, Torbjørn Lindahl

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.