This is to get around Perl's 'indirect object syntax'.
Otherwise
ok Mock::Basic->update(...);
looks like
Mock::Basic->ok->update(...);
which is probably not what is intended.
ok(Mock::Basic->update(...)); works as well. | [reply] [d/l] [select] |
ok, and how does + "get around" it? What exactly is syntactically happening?
Is "ok" being added to "Mock::Basic->update(...)"
| [reply] [d/l] |
| [reply] |
perl -MCGI -MTest::More -e " ok 1; ok +CGI->new, +CGI->new; ok scalar
+CGI->new; ok( CGI->new ); ok CGI->new; "
ok 1
ok 2 - CGI=HASH(0x1a08a30)
ok 3
ok 4
Undefined subroutine CGI::ok
at -e line 1
# Tests were run but no plan was declared and done_testing() was not s
+een.
| [reply] [d/l] |
It tells the parser "Hi. Since I have a leading (unary) plus sign, I'm now a scalar expression, so I qualify to match the first item in ok()'s prototype; please do not get confused and interpret me as a class name you should call an ok() method on."
This was done to avoid putting the parens around ok()'s argument, like this:
ok(
Mock::Basic->update(
'mock_basic',
{ name => 'python' },
{id => 1}
),
'I should actually put a description on this test'
);
To me this is a lot clearer; it's less mental effort to just add the parens than it is to dork around trying to remember the parsing rules. Once the parens are there, we've unambiguously declared "these are arguments to a subtroutine called ok(). Please to not attempt to interpret it otherwise, thank you." I'll igonore the fact that there's no description on the test - I think that's more objectionable than the syntax trickery, frankly.
Perhaps you should file a bug on that - feel free to snag this rewrite as a start on a patch. | [reply] [d/l] |
Apparently, there's ambiguity in the parser that does not get resolved as desired.
a b->c()
desired: a( b->c() )
actual: ( b->a() )->c()
unary-plus is a no-op, but it changes what the compiler sees from a bareword to an operator. That removes the ambiguity.
Using parens around the parameters (ok( ... )) would also remove the ambiguity.
- ikegami
| [reply] [d/l] [select] |