Description

Akin to Google's former Code Search, this aims to search all the code found on CPAN. It concentrates on searching code; if you just want to look for a module use MetaCPAN instead.

Regular Expressions are supported via re::engine::RE2 (which wraps Google's RE2 engine). This means that the regexps supported are mostly Perl compatible but are not totally compatible with Perl. Of particular note is look-ahead and look-behind are not supported, for more details see RE2's supported syntax.

(Due to performance concerns re::engine::RE2's ability to fallback to Perl regexps is disabled.)

Syntax

The following operators are supported, they accept regexps (after the colon) and can be negated with a - prepended to their name. Anything that does not match this syntax will be treated as a regexp on the code itself.

A useful shortcut for these operators is to use '=' rather than ':' as a separator, this does a full string match (i.e. wraps anchors around the supplied regexp).

For example -dist=perl to exclude perl, file:.xs to search only XS files or -file:"ppport\.h" to exclude ppport.h.

Much of the power of this tool comes from the fact that raw regexps can be used. By default the search is case sensitive, but (?i) or (?i:regexp) syntax can be used to make it case insensitive. Escapes such as \n can be used to match on newlines or the (?s) modifier (be careful with this, very greedy matching is limited for resource reasons, you may find writing a regexp such as .{1,10} rather than blindly writing .* is more effective).

Examples

A picture is worth a thousand words:

(If you find any more good examples please send them my way.)

API

There is an experimental API (i.e. subject to change), using the same syntax as the normal searches at: http://grep.cpan.me/api?q=. For example: http://grep.cpan.me/api?q=-dist=perl+GvCV. If you expect to make heavy usage of this please ensure you send a User-Agent header that describes your application (ideally with contact details) and send a mail to the mailing list so we can keep track of users.

Misc

Written by David Leadbeater. For help use the cpangrep mailing list or ask me (dg) on irc.perl.org, #toolchain.

Contributions are welcome; you can find the git repository at github (including the issue tracker).

Thanks to taras for help with graphics and layout.
Home · About