Pitonyak::SafeGlob - Regular expressions and file specs for finding files and directories.
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";
}
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()
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!
Set the attribute if a parameter is present.
Return the state of the parameter.
copy($object)
Make a copy of this object
$obj1-
copy($obj2)> is the same as $obj1 = $obj2
.
Remember that the call $obj->method(@parms)
is the same as
method($obj, @parms)
.
If there is only one paramter, the first parameter is assumed to be an attribute name and the default attribute value is returned.
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.
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.
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.
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.
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.
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([@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.
Set the attribute if a parameter is present.
Return the state of the parameter.
Set the attribute if a parameter is present.
Return the state of the parameter.
Set the attribute if a parameter is present.
Return the state of the parameter.
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.
Change some wording, and a few minor fixes such sa removing references to a logger.
Use File::Spec to concatinate a directory path to a file name. This is a safer than the previous assumptions. Corrected POD documentation.
Version 1.01 Changed internal documentation to POD documentation and support subdirectories
Version 1.00 First release