New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spec test suite #33

Closed
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@paultcochrane
Contributor

paultcochrane commented Feb 24, 2016

It turns out that the spec test suite had two failures when running with Perl 5.16 and below, however tested correctly on 5.18 and above. These patches fix this problem allowing the test suite to run correctly in all Perl versions. More detailed information about the fix is available in the commit messages. This code has been checked on Perls 5.8 through 5.22.

paultcochrane added some commits Feb 24, 2016

Fix spec test suite breakages
The spec test suite (`t/001_spec_compatibility`) was breaking in Perl
versions 5.16 and below on the "Sections" test within `delimiters.yml` and
and the "Nested (Truthy)" test in `sections.yml` with the error

    Can't call method "can" without a package or object reference

The issue was that the `$ctx` variable being used within the `lookup()`
function could be a simple as the value `1`.  The original code would then
attempt to call `->can($field)` on this value, hence causing the error
mentioned above and hence the test failures.  By running the `->can()` call
within an `eval` block, we can catch the error, and if the error occurs,
then specify a false value for the ability to run the `can()` method, which
implements - I believe - the desired behaviour.

However, the ability to run `can()` with or without error is dependent upon
the version of Perl; versions 5.16 and below raise an error, 5.18 and above
return `undef`.  Hence the decision about whether or not the current value
of the `$ctx` variable can run the given `$field` as a method or not needs
to be handled appropriately.  This can be done with named subroutine which
calls the error-handling code for Perl versions 5.16 and below, and for Perl
versions above 5.16 the original `$ctx->can($field)` code can be used.
Extract a boolean operation into a variable
The check to see if the variable `$ctx` is blessed or if it is not a
reference is one unit of a conditional branch in the `lookup()` function.
Extracting this into a variable makes the conditional branch now easier to
read and interpret.
@yanick

This comment has been minimized.

Show comment
Hide comment
@yanick

yanick Nov 6, 2016

Owner

Thanks!

Owner

yanick commented Nov 6, 2016

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment