LanX has asked for the wisdom of the Perl Monks concerning the following question:
is there a way to tell the compiler to parse barewords (when allowed) as sub-calls and not as strings w/o predeclaring them?
use strict; use warnings; use feature 'say'; our $AUTOLOAD; sub AUTOLOAD { say "Autoload called as $AUTOLOAD(@_)" } BLA(1,2,3); no strict 'refs'; # BLA 1,2,3;
I'm experimenting with internal DSLs and am also looking at some Ruby examples.
Since Ruby never tries to interpret barewords as strings¹ it tries to call it's own version of AUTOLOAD() there ( IIRC .missing_method())
For this in Perl I need to use parens.
Uncommenting BLA in the code example leads to error with Do you need to predeclare BLA
Many DSLs profit (i.e. have much more syntactic sugar) if calls are not necessarily predeclared.
Semantically it's a way to avoid method syntax in a special context, i.e instead of writing
$myDSL->BLA + $myDSL->FOO
I can use
within_myDSL { BLA + FOO }
But ATM I can only achieve
within_myDSL { BLA() + FOO() }
I don't have much hope here, but asking shouldn't be a sin.
Cheers Rolf
( addicted to the Perl Programming Language)
¹) In Perl a (non strict) heritage from shell scripting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing barewords as sub/method calls?
by hdb (Monsignor) on Nov 23, 2013 at 18:01 UTC | |
by LanX (Saint) on Nov 23, 2013 at 18:25 UTC | |
|
Re: Parsing barewords as sub/method calls? (workaround)
by LanX (Saint) on Nov 23, 2013 at 16:54 UTC | |
by Corion (Patriarch) on Nov 23, 2013 at 17:14 UTC | |
by Eily (Monsignor) on Nov 23, 2013 at 17:21 UTC | |
|
Re: Parsing barewords as sub/method calls?
by oiskuu (Hermit) on Nov 23, 2013 at 17:43 UTC | |
by LanX (Saint) on Nov 23, 2013 at 17:48 UTC | |
by oiskuu (Hermit) on Nov 23, 2013 at 19:11 UTC | |
by LanX (Saint) on Nov 23, 2013 at 19:28 UTC |