++ed by:
TOBYINK AZAWAWI

2 PAUSE user(s)

Guillaume Aubert

NAME

String::InterpolatedVariables - Extract variable names from interpolated strings.

VERSION

Version 1.0.4

SYNOPSIS

        use String::InterpolatedVariables;

        my $variables = String::InterpolatedVariables::extract(
                'A $test->{string} from a PPI::Token::Quote::Double $object.'
        );

        # $variables now contains:
        # [
        #     '$test->{string}',
        #     '$object',
        # ]

DESCRIPTION

String::InterpolatedVariables offers a way to extract the name of the variables that are present in interpolated strings.

This is particularly useful if you are using PPI to parse Perl documents, and you want to know what variables would be interpolated inside the PPI::Token::Quote::Double and PPI::Token::Quote::Interpolate objects you find there. A practical example of this use can be found in Perl::Critic::Policy::ValuesAndExpressions::PreventSQLInjection.

FUNCTIONS

extract()

Extract variables from interpolated strings.

        my $variables = String::InterpolatedVariables::extract(
                'A $test->{string} from a PPI::Token::Quote::Double $object.'
        );

        # $variables now contains:
        # [
        #     '$test->{string}',
        #     '$object',
        # ]

Note that you need to pass the text of the string, even if the string itself is destined to be interpolated. In other words, passing "Test $test" would not find any variables, as $test would get interpolated by Perl before the string is passed to the extract() function. This function is thus more useful if you are using using a tool such as PPI to read Perl code, since PPI will give you access to the text of the string itself for strings that would otherwise be interpolated during execution.

BUGS

Please report any bugs or feature requests through the web interface at https://github.com/guillaumeaubert/String-InterpolatedVariables/issues. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

        perldoc String::InterpolatedVariables

You can also look for information at:

AUTHOR

Guillaume Aubert, <aubertg at cpan.org>.

COPYRIGHT & LICENSE

Copyright 2014 Guillaume Aubert.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/