File::CodeSearch - Search file contents in code repositories
This documentation refers to File::CodeSearch version 0.5.1.
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);
new ( %params )
Parameters:
regex
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 and F::C::Replacer modules interchangeably with F::C::RegexBuilder.
F::C::Highlighter
F::C::Replacer
F::C::RegexBuilder
files
If you desire to limit files by file type, name, symlink status pass this object, other wise a default object will be created.
recurse
Set to false to not recurse into sub directories.
breadth
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
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 and depth are both true breadth will be used.
suround_before
Specifies the maximum number of lines before a match is found that should be passed to the searching code reference.
suround_after
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
Stops matching after limit matches have been found across all files that have been searched.
Return: File::CodeSearch - new object
File::CodeSearch
Description: Creates & configure a File::CodeSearch object.
search ( $search, @dirs )
Arguments:
$search
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
The line from the file that was matched by regex. If searching with after set this may be undefined when called with the lines found after the last match at the end of the file.
after
$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
An array of lines that were found before the matched line.
An array of lines that were found after the last matched line.
lines
An array of lines of the file. This is only present if regex is a F::C::Replacer object.
parent
The parent path from @path
@dir
An array of the directory paths to search through.
Return:
Description:
search_file ( $search, $file, $parent )
Param:
See search above for details.
search
A file to search through line by line
$parent
The directory from @dirs which the file was found in
Description: Searches an individual file for matches.
There are no known bugs in this module.
Please report problems to Ivan Wills (ivan.wills@gmail.com).
Patches are welcome.
Ivan Wills - (ivan.wills@gmail.com)
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.
To install File::CodeSearch, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::CodeSearch
CPAN shell
perl -MCPAN -e shell install File::CodeSearch
For more information on module installation, please visit the detailed CPAN module installation guide.