Skip to content

reneeb/Text-Find-Scalar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Kwalitee status GitHub issues

NAME

Text::Find::Scalar - Find scalar names in a text.

VERSION

version 0.10

SYNOPSIS

use Text::Find::Scalar;

my $finder = Text::Find::Scalar->new();
my $arrayref = $finder->find($string);

# or

$finder->find($string);
while($finder->hasNext()){
  print $finder->nextElement();
}

DESCRIPTION

This class helps to find all scalar variables in a text. It is recommended to use PPI to parse Perl programs. This module should help to find SCALAR names e.g. in error messages.

Scalars that should be found:

  • double quoted

      "$foo"
    
  • references

      $foo->{bar}
    
  • elements of arrays

      $array[0]
    

Scalars that are not covered

  • single quoted

      '$foo'
    

EXAMPLE

#!/usr/bin/perl

use strict;
use warnings;

use Text::Find::Scalar;

my $string = q~This is a $variable
       another $variable and another "$eine", but '$no' is not found.
       A $reference->{$key} is found. An array element $array[0]
       is also found~;

my $finder = Text::Find::Scalar->new();
my @scalars = $finder->find($string);

print $_,"\n" for(@scalars);

prints

/homes/reneeb/community>find_scalar.pl
$variable
$variable
$eine
$reference->{$key}
$array[0]

METHODS

new

my $finder = Text::Find::Scalar->new();

creates a new Text::Find::Scalar object.

find

my $string = q~Test $test $foo '$bar'~;
my $arrayref = $finder->find($string);
my @found    = $finder->find($string);

parses the text and returns an arrayref that contains all matches.

hasNext

while($finder->hasNext()){
  print $finder->nextElement();
}

returns 1 unless the user walked through all matches.

nextElement

print $finder->nextElement();
print $finder->nextElement();

returns the next element in list.

unique

my $uniquenames = $finder->unique();

returns an arrayref with a list of all scalars, but each match appears just once.

count

my $counter = $finder->count('$foo');

returns the number of appearances of one scalar.

Development

The distribution is contained in a Git repository, so simply clone the repository

$ git clone git://github.com/reneeb/Text-Find-Scalar.git

and change into the newly-created directory.

$ cd Text-Find-Scalar

The project uses Dist::Zilla to build the distribution, hence this will need to be installed before continuing:

$ cpanm Dist::Zilla

To install the required prequisite packages, run the following set of commands:

$ dzil authordeps --missing | cpanm
$ dzil listdeps --author --missing | cpanm

The distribution can be tested like so:

$ dzil test

To run the full set of tests (including author and release-process tests), add the --author and --release options:

$ dzil test --author --release

AUTHOR

Renee Baecker reneeb@cpan.org

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Renee Baecker.

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

About

Perl module to find scalars in a given text.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages