develooper Front page | perl.perl5.porters | Postings from October 2021

Re: v5.36, indirect, and multidimensional

Thread Previous | Thread Next
From:
Graham Knop
Date:
October 11, 2021 14:27
Subject:
Re: v5.36, indirect, and multidimensional
Message ID:
CAM=m89Hfedu_BOvHEKj96ax7-vgDroTzW6t=HstUB9bwX-jhoA@mail.gmail.com
On Mon, Oct 11, 2021 at 2:39 PM Nicolas Mendoza <mendoza@pvv.ntnu.no> wrote:
>
> Note that using 'no indirect' basically just is what one would expect "use warnings 'indirect'" would've done.
>
> I just realized I can't ensure all "indirect"-like syntax is treated as function calls (or other fitting syntax), which was what I really expected from the pragma/module.
>
> Example code from a bug report I didn't submit now since I recalled the "indirect" chapter here:
>
> Expected output is a silent:
>
> ```
> foo
> bar
> baz
>
> ```
>
> ```
> $ cat /tmp/no_no_indirect.t
>
> #!/usr/bin/env perl
>
> use v5.30;
> no indirect;
>
> use Path::Tiny;
>
> sub p {
>   say shift;
> }
>
> say Path::Tiny->new("foo");
> p "bar";
> p Path::Tiny->new("baz");
> ```
>
> ```
> $ perl /tmp/no_no_indirect.t
> Indirect call of method "p" on object "Path::Tiny" at /tmp/no_no_indirect.t line 14.
> foo
> bar
> Can't locate object method "p" via package "Path::Tiny" at /tmp/no_no_indirect.t line 14.
>
> ``
>
> [/quote]

This is using the indirect CPAN module. I don't believe it is possible
for a CPAN module to impact the parsing enough to prevent any code
from being parsed as indirect, and can only do checks on the result.
The core feature "no feature 'indirect';" works as you desire. It is
unfortunate that these two have different behavior, but it seems
unavoidable.

It could be nice to have "use warnings 'indirect';" as a separate
addition. Being able to fail on indirect calls, rather than silently
treating them as function calls, can be valuable for writing code that
is meant to work on older perl versions.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About