
File::CodeSearch - Search file contents in code repositories

This documentation refers to File::CodeSearch version 0.5.6.

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 - File::CodeSearch::RegexBuilderThis 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.
files - File::CodeSearch::FilesIf you desire to limit files by file type, name, symlink status pass this object, other wise a default object will be created.
recurse - BoolSet to false to not recurse into sub directories.
breadth - BoolChanges 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 - BoolChanges 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 - IntSpecifies the maximum number of lines before a match is found that should be passed to the searching code reference.
suround_after - IntSpecifies 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 - IntStops 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 refSubroutine 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 - stringThe 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.
$fileThe file name that the line was found in (relative to the supplied directory
$line_numberThe line number in the said file
%namedThis contains all the other helpful values
codesearch - F::CodeSearchThe object that is doing the searching.
before - ArrayRefAn array of lines that were found before the matched line.
after - ArrayRefAn array of lines that were found after the last matched line.
lines - ArrayRefAn array of lines of the file. This is only present if regex is a F::C::Replacer object.
parent - pathThe parent path from @path
@dir - pathsAn array of the directory paths to search through.
Return:
Description:
search_file ( $search, $file, $parent )Param:
$search - CodeRefSee search above for details.
$file - fileA file to search through line by line
$parent - pathThe 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.