You've gotta quotemeta!

Seriously, if you are going to interpolate a filename into a string that is to be used as a regex pattern, you must use quotemeta. That is, just surround the filename with \Q and \E. It doesn’t take much, but it does prevent unforced errors.

So, after building my shiny new Perl 5.20.1 with the Community Edition of Visual Studio 2013, I did a:

C:\Users\user> cpanm Moo Template Mojolicious

After a few minutes, I looked, and saw that a bunch of dependencies had failed to build.

First to catch my attention was Test::LeakTrace — odd because the test files giving the problems were written more than five years ago, but I didn’t run into this problem with any of the previous times I installed the aforementioned modules. … A-ha! Template Toolkit started checking for leaks.

What are these tests that are failing in Test::LeakTrace? Glad you asked. Here is one:

like __FILE__, qr/$si->[1]/, 'state info'
    or diag(Dumper \@info);

And the others are here, here, here, and here.

Yeah, sure, I am going to put together a patch … but … seriously?!

PS: Rather curiously, Test::Fatal also fails tests. See if you can spot the reason:

#   Failed test '$TODO works'
#   at t\todo.t line 110.
# STDOUT is:
# not ok 1 - succeeded # TODO unimplemented
# #   Failed (TODO) test 'succeeded'
# #   at t\todo.t line 108.
# #          got: '0'
# #     expected: '1'
# ok 2 - no exceptions # TODO unimplemented
# ok 3 - level 1 # TODO unimplemented
#
# not:
# not ok 1 - succeeded # TODO unimplemented
# #   Failed (TODO) test 'succeeded'
# #   at t/todo.t line 108.
# #          got: '0'
# #     expected: '1'
# ok 2 - no exceptions # TODO unimplemented
# ok 3 - level 1 # TODO unimplemented
#
# as expected

Now, this file also has not changed in a long time. Presumably, the way the filename is formatted for the failure message changed recently, but I am not in the mood for a long, uncertain git bisect session.

Of course, the solution to this problem has nothing to do with quotemeta, but I just could not bring myself to put together another blog post.