View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Moritz Onken > Test-File-Content-1.0.1 > README.pod


Annotate this POD


View/Report Bugs
Source   Latest Release: Test-File-Content-1.0.2


 use Test::File::Content;
 use Test::More;
 content_like( qr/\.pm/, qr/^#\s*ABSTRACT/, 'lib' );
 content_like( pm => '__PACKAGE__->meta->make_immutable', 'lib/MooseClasses' );
     js => {
         'console.log debug statement' => 'console.log',
         'never use alert' => qr/[^\.]alert\(/,
     tt => [
        qr/\[% DUMP/,
     pl => '\$foo',
 }, qw(lib root/templates jslib));

Example output:

 not ok 1 - lib/
 #   Failed test 'lib/'
 # file lib/ does not contain (?-xism:^#\s*ABSTRACT)
 ok 2 - lib/MooseClasses/
 not ok 3 - jslib/test.js
 #   Failed test 'jslib/test.js'
 # console.log debug statement found in jslib/test.js line 1
 # console.log debug statement found in jslib/test.js line 2
 ok 4 - root/templates/


When writing code, I tend to add a lot of debug statements like warn or Data::Dumper. Occasionally I name my variables $foo and $bar which is also quite a bad coding style. JavaScript files may contain console.log() or alert() calls, which are equally bad.

This test can help to find statements like these and ensure that other statements are there.


The following functions are exported by default:



Arguments: \%config, @directories

Arguments: $filter, $rule, @directories

%config consists of key value pairs where each key is a file extension (e.g. .pm) and the value is a $rule.

$filter can either be a string literal (like the key of %config), an arrayref of extensions, a regular expression or even a coderef. The coderef is passed the filename as argument and is expected to return a true value if the file should be looked at.

$rule can be a string literal, an arrayref of rules or a regular expression.

@directories contains a list of directories or files to look at.

syntax highlighting: