An example to illustrate is the Synopsis of my own Test::Version.
use Test::More;
use Test::Version 0.04;
# test blib or lib by default
version_all_ok();
done_testing;
I don’t have to include parenthesis on done_testing(); I can simply call it. However when I’ve tried to call version_all_ok; ( note: First attempt at Dist::Zilla::Plugin::Test::Version failed this way) I get an error. Why is this?
Update Perhaps my example is not quite as good as I’ve thought. The actual error I’ve gotten is
Bareword "version_all_ok" not allowed while "strict subs" in use at t/release-test-version.t line 19.
and here’s the full code
#!/usr/bin/perl
BEGIN {
unless ($ENV{RELEASE_TESTING}) {
require Test::More;
Test::More::plan(skip_all => 'these tests are for release candidate testing');
}
}
use 5.006;
use strict;
use warnings;
use Test::More;
eval "use Test::Version";
plan skip_all => "Test::Version required for testing versions"
if $@;
version_all_ok; # of course line 19, and version_all_ok() works here.
done_testing;
The following should be relevant snippets pulled from Test::Version 1.0.0 for exportation.
use parent 'Exporter';
our @EXPORT = qw( version_all_ok ); ## no critic (Modules::ProhibitAutomaticExportation)
our @EXPORT_OK = qw( version_ok );
Fundamentally, because Perl needs to know that a bareword means a function call in order to parse it as a function call. There are two ways Perl might learn this interesting fact:
You might have decorated the bareword like a function call, prepending
&or->or appending(...)or both. Perl will trust that you know what you’re talking about and parse the bareword as a function call even if it doesn’t yet know what function it will have to call.You might have declared a function with that name before Perl tries to parse the call. Ordinarily,
use-ing a module is enough to ensure the symbols get created at the right time; you’re doing something wrong inTest::Versionsuch that the symbol is not getting exported until after it is needed to compile the test script.In your code, you wrap the
useinside aneval, which effectively delays it until execution time. Consequently, the symbolversion_all_okis not available when Perl tries to compile the call and it blows up. Forcing theevalto compile time should suffice to make the symbol available: