NAME

PPIx::Literal - Convert PPI nodes into literal values

VERSION

version 0.1.0

SYNOPSIS

use PPI;
use PPIx::Literal;

my $doc    = PPI::Document->new( \q{(1, "one", 'two')} );
my @values = PPIx::Literal->convert($doc);
# (1, "one", "two")

my $doc    = PPI::Document->new( \q{ [ 3.14, 'exp', { one => 1 } ] } );
my @values = PPIx::Literal->convert($doc);
# [3.14, "exp", { one => 1 }]

my $doc    = PPI::Document->new( \q{use zim 'Carp' => qw(carp croak)} );
my ($use)  = $doc->children;
my @values = PPIx::Literal->convert( $use->arguments );
# ("Carp", "carp", "croak")

DESCRIPTION

This code is alpha quality. It is an early release.
Interface may change. There may be serious bugs.

This module implements the conversion of a small subset of Perl into their literal values. The perl code to be converted is represented as a list of PPI nodes.

The conversion works for pieces which gets built from literal tokens and which don't require any kind of compilation.

Some examples are:

42          # number
"a + b"     # plain strings
qw(a b c)   # quoted words

[]                          # anon array refs
{ -version => '0.3.2' },    # anon hash refs
(2, 3, 4)                   # literal lists

The result of the conversion is a list of Perl data structures which contain plain scalars and "unknowns" as leafs. The "unknowns" are used to represent PPI nodes which can't be converted to literals.

METHODS

PPIx::Literal implements the following methods.

convert

@values = PPIx::Literal->convert(@nodes);

Convert @nodes into their literal values or into "unknowns".

SEE ALSO

PPI

AUTHOR

Adriano Ferreira <ferreira@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Adriano Ferreira.

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