NAME

Pitonyak::SafeGlob - Regular expressions and file specs for finding files and directories.


SYNOPSIS

File and directory scanning based on regular expressions.

use Pitonyak::SafeGlob;

my @full_specs = ('c:\*.txt', 'C:\Andy\Dev\Perl\Pitonyak\*.p?');
my @file_specs = ('*.pl', '*.pm');
my @file_regs = ('.*\.pl$', '.*\.pm$');
my @files;

my $g = new Pitonyak::SafeGlob;

$g->case_sensitive(1);
$g->return_dirs(0);
$g->return_files(1);
foreach ($g->glob_spec_from_path(@full_specs))
{
# Full path to file returned.
print "spec from path => $_\n";
}

foreach ($g->glob_spec('c:\Andy\Dev\Perl\Pitonyak', @file_specs))
{
print "glob_spec => $_\n";
}

foreach ($g->glob_regex('c:\Andy\Dev\Perl\Pitonyak', @file_regs))
{
print "glob_regex => $_\n";
}


DESCRIPTION

There was a time when glob() returned an empty list if there were too many files in a directory. This module avoids this problem.

In the following routines, if the $use_case parameter evaluates to true, then matching will be done in a case sensitive manner. Matches are not case sensitive otherwise.

In the following routines, if the $include_files parameter evaluates to true, then files that match will be returned.

In the following routines, if the $include_dirs parameter evaluates to true, then directories that match will be returned.

new

new()

Note that this is written in such a manner that it can be inherited. Also note that it is written such that $obj2 = $obj1->new() is valid!

case_sensitive

case_sensitive([0|1])

Set the attribute if a parameter is present.

Return the state of the parameter.

copy

copy($object)

Make a copy of this object

$obj1-copy($obj2)> is the same as $obj1 = $obj2.

get_class_attribute

Remember that the call $obj->method(@parms) is the same as method($obj, @parms).

SafeGlob::get_class_attribute($attribute_name)

If there is only one paramter, the first parameter is assumed to be an attribute name and the default attribute value is returned.

$obj->get_class_attribute($attribute_name)

If there are two parameters, then the first parameter is assumed to be a SafeGlob object and the second parameter is assumed to be an attribute name. The attribute value for the object is returned.

$obj->get_class_attribute($attribute_name, $attribute_value)

If three parameters are given, then the first parameter is the object, the second parameter is used to set a new value for the attribute, and the third parameter is the attribute name, The attribute value is then returned.

glob_regex

glob_regex($path, [@regular_expressions])

All regular expressions are assumed to follow the path. This returns the files and/or directories that match the regular expression in the given path. The directory tree is recursed if the recursion flag is set.

glob_regex_dirs

glob_regex_dirs($path, [@dir_regular_expressions])

All regular expressions are assumed to follow the path. This returns the directories that match the regular expression in the given path. Recursion is done if the recurse parameter is set.

glob_regex_files

glob_regex_files($path, [@file_regular_expressions])

All regular expressions are assumed to follow the path. This returns the files that match the regular expression in the given path. Recursion is done if the recurse parameter is set.

glob_spec

glob_spec($path, [@file_specs])

All file specs are assumed to follow the path. The file specs are turned into regular expressions and then glob_regex is called. This returns the files that match the file specification in the given path.

glob_spec_from_path

glob_spec_from_path([@file_specs_with_dirs])

This assumes that it is given a list of file specs where the file specs contain leading directory entries. The file spec and path are separated using File::Basename::fileparse() and then glob_spec is called.

recurse

recurse([0|1])

Set the attribute if a parameter is present.

Return the state of the parameter.

return_dirs

return_dirs([0|1])

Set the attribute if a parameter is present.

Return the state of the parameter.

return_files

return_files([0|1])

Set the attribute if a parameter is present.

Return the state of the parameter.


COPYRIGHT

Copyright 1998-2006, Andrew Pitonyak (perlboy@pitonyak.org)

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


Modification History

July 17, 2009

Change some wording, and a few minor fixes such sa removing references to a logger.

April 4, 2007

Use File::Spec to concatinate a directory path to a file name. This is a safer than the previous assumptions. Corrected POD documentation.

September 10, 2002

Version 1.01 Changed internal documentation to POD documentation and support subdirectories

March 13, 1998

Version 1.00 First release