Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: I would have expected a syntax error here

by LanX (Saint)
on Oct 19, 2018 at 16:50 UTC ( [id://1224347]=note: print w/replies, xml ) Need Help??


in reply to Re: I would have expected a syntax error here
in thread Solved! I would have expected a syntax error here

To elabotate further:

the odd words to today are considered packages, the even ones got here methods.

Both are not required to exist at compile time.

It's a variation of new Class arg-list just twice.

Hence got To (here Today () ) (capitalizing classes for clarity)

Nb: If the bare words where already pre defined subs, Perl would parse them differently.

I see two solutions:

  • a possible pragma to forbid indirect method calls (becoming standard in Perl 7)
  • a module which is parsing the op-tree at the CHECK phase warning about undefined packages. (dynamic package creation at runtime is rare)

the latter could be implemented right away.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^3: I would have expected a syntax error here
by Corion (Patriarch) on Oct 19, 2018 at 17:37 UTC

    indirect already exists on CPAN:

    >perl -M-indirect -wle "got to here today! (20180520)" Indirect call of method "here" on object "today" at -e line 1. Indirect call of method "got" on object "to" at -e line 1. Can't locate object method "here" via package "today" (perhaps you for +got to load "today"?) at -e line 1.
    >perl -wle "got to here today! (20180520)" Can't locate object method "here" via package "today" (perhaps you for +got to load "today"?) at -e line 1.

    You can put it either into PERL5OPT or just at the top of your code:

    no indirect;

      Corion:

      While I'm going to try to use the yadda operator, I think I'll stick this in my PERL5OPT since:

      1. I'm already using PERL5OPT,
      2. who knows how many of these bombs may be ticking on my hard drive, and
      3. I don't know how long it'll take me to get into the habit of using ...

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

      Nice ...

      ... but I think it should allow to add new as exception. (couldn't find it)

      There is far too much legacy code using an indirect new as constructor.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        You don't need to make it fatal and you also don't need to enable it globally.

        If it is for your own code, you can slowly fix that code, eliminating those warnings.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1224347]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found