NAME
File::CodeSearch - Search file contents in code repositories
VERSION
This documentation refers to File::CodeSearch version 0.7.6.
SYNOPSIS
use File::CodeSearch;
# Simple usage
code_search {
my ($file, $line) = @_;
# do stuff
},
@dirs;
# More control
my $cs = File::CodeSearch->new();
$cs->code_search(sub {}, @dirs);
DESCRIPTION
SUBROUTINES/METHODS
new ( %params )
Parameters:
regex
- File::CodeSearch::RegexBuilder-
This is the object that handles the testing of individual lines in a file and must be created with the search options desired, note you can also use the
F::C::Highlighter
andF::C::Replacer
modules interchangeably withF::C::RegexBuilder
. files
- File::TypeCategories-
If you desire to limit files by file type, name, symlink status pass this object, other wise a default object will be created.
recurse
- Bool-
Set to false to not recurse into sub directories.
breadth
- Bool-
Changes the search order to breadth first i.e. the searching will search all the ordinary files in a directory before searching the directories. The default is to search directories when they are found.
depth
- Bool-
Changes the search order to depth first i.e. the searching will search all the sub directories in a directory before searching the ordinary files. The default is to search directories when they are found. If both
breadth
anddepth
are both truebreadth
will be used. suround_before
- Int-
Specifies the maximum number of lines before a match is found that should be passed to the searching code reference.
suround_after
- Int-
Specifies the maximum number of lines after a match is found that should be passed to the searching code reference. Note the after match lines are passed to the next matched line in a file or to a call at the end of a file with matches.
limit
- Int-
Stops matching after
limit
matches have been found across all files that have been searched.
Return: File::CodeSearch
- new object
Description: Creates & configure a File::CodeSearch
object.
search ( $search, @dirs )
Arguments:
$search
- code ref-
Subroutine to be executed each time a match in a file is found.
The subroutine should have accept parameters as
$search->($line, $file, $line_number, %named);
$line
- string-
The line from the file that was matched by
regex
. If searching withafter
set this may be undefined when called with the lines found after the last match at the end of the file. $file
-
The file name that the line was found in (relative to the supplied directory
$line_number
-
The line number in the said file
%named
-
This contains all the other helpful values
codesearch
-F::CodeSearch
-
The object that is doing the searching.
before
- ArrayRef-
An array of lines that were found before the matched line.
after
- ArrayRef-
An array of lines that were found after the last matched line.
lines
- ArrayRef-
An array of lines of the file. This is only present if
regex
is aF::C::Replacer
object. parent
- path-
The parent path from @path
@dir
- paths-
An array of the directory paths to search through.
Return:
Description:
search_file ( $search, $file, $parent )
Param:
$search
- CodeRef-
See
search
above for details. $file
- file-
A file to search through line by line
$parent
- path-
The directory from @dirs which the file was found in
Description: Searches an individual file for matches.
DIAGNOSTICS
CONFIGURATION AND ENVIRONMENT
DEPENDENCIES
INCOMPATIBILITIES
BUGS AND LIMITATIONS
There are no known bugs in this module.
Please report problems to Ivan Wills (ivan.wills@gmail.com).
Patches are welcome.
AUTHOR
Ivan Wills - (ivan.wills@gmail.com)
LICENSE AND COPYRIGHT
Copyright (c) 2009-2011 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. 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.