Hi

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;

motivation

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


In reply to Parsing barewords as sub/method calls? by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.