Kent Fredric

NAME

Paludis::ResumeState::Serialization::Grammar - A Regexp::Grammars grammar for parsing Paludis Resume-states

VERSION

version 0.01000410

METHODS

grammar

    my $grammar = Paludis::ResumeState::Serialization::Grammar::grammar();
    if( $data =~ $grammar ){
        do_stuff_with(\%/);
    }

Returns a grammar regular expression object formed with Regexp::Grammars.

To tune the data it provides, localise "$CLASS_CALLBACK" and "$LIST_CALLBACK".

CLASS VARIABLES

The following variables may be localised and assigned to subs as callbacks to tune how the regular expressions grammar works.

$CLASS_CALLBACK

    local $Paludis::ResumeState::Serialization::Grammar::CLASS_CALLBACK = sub {
        my ( $name, $parameters, $parameters_list, $extra ) = @_;
        return { whatever }
    };

This callback is called every time a parse completes a 'class' entry, allowing you to filter it however you want.

WARNING Regexp::Grammars states that during the traversal of a grammar, you really should avoid calling anything that itself uses regular expressions, as it could be broken, or interfere with the grammars parsing.

This includes Moose due to it using Regular Expressions for type-constraints.

If you need an advanced processing, its recommended to do just enough to identify the instance later, and then pass over the data and do the powerful magic after the grammar has run its course.

$name

Is the name of the class we most recently discovered.

$parameters

Is a hash-ref of all the classes parameters, treated as a key-value set.

    Foo(key=value;bar=baz;quux=doo;);

Thus produces

    { bar => 'baz', key => 'value', quux => 'doo' }

$parameters_list

Similar to $parameters, but optimised to preserve ordering and preserve format.

    [ ['key', 'value' ], [ 'bar' , 'baz' ], ['quux', 'doo' ] ]

$extras

Periodically, the parser may return a few extra bits of data that don't fall under the usual classifications. At present, its only the pid property of the ResumeData object, i.e.:

    ResumeData@1234(foo=bar;);

Will arrive as

    $code->('ResumeData', { foo  => 'bar' }, [['foo','bar']], { pid => '1234' });

$LIST_CALLBACK

    local $Paludis::ResumeState::Serialization::Grammar::LIST_CALLBACK = sub {
        my ( $parameters ) = @_;
        return { whatever }
    };

Paludis resume files have a special case class which behaves like a list:

    Foo(bar=c(1=baz;2=quux;3=doo;count=3;););

We detect this intent and pass it to $LIST_CALLBACK as an array.

    $code->(['baz','quux','doo' ]);

AUTHOR

Kent Fredric <kentnl@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Kent Fredric <kentnl@cpan.org>.

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




Hosting generously
sponsored by Bytemark