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

Re: v5.36, indirect, and multidimensional

Thread Previous | Thread Next
From:
Nicolas Mendoza
Date:
October 11, 2021 12:38
Subject:
Re: v5.36, indirect, and multidimensional
Message ID:
faf1c91f-2c39-3302-931a-08fb757dbed7@pvv.ntnu.no

Den 08.10.2021 21:24, skrev Ricardo Signes:
> Porters,
>
> On today's PSC call, we were discussing the state of the "use v5.36" 
> bundle, and whether it should turn off the "indirect" and 
> "multidimensional" features.  Our consensus was that this 
> *should* happen. For those who want a refresher:
>
> "no feature 'indirect'" disables "indirect object syntax" meaning you 
> can no longer write this:
> my $object = new Class (1, 2);
>
> This is useful as a footgun remover, converting a mistake from runtime 
> to compile time.  For example, say you're like me and often forget to 
> load Try::Tiny…
> dinah:~$ perl -c -e 'try {1 };'
> -e syntax OK
>
> dinah:~$ perl  -e 'try {1 };'
> Can't locate object method "try" via package "1" (perhaps you forgot to load "1"?) at -e line 1.
>
> dinah:~$ perl -c -e 'no feature "indirect"; try {1 };'
> syntax error at -e line 1, near "try {"
> -e had compilation errors.
>
> The first two stanzas show the current behavior: the code compiles but 
> won't run.
>
> The third shows the behavior without indirect: it fails to compile.
>
> This syntax has long been discouraged.  Existing code will continue to 
> work, and this will only affect code that disables the syntax.  Some 
> example code in documentation may now be "wrong" when put into place 
> with use v5.36.0 in place, but that's a risk we're already taking with 
> other features.
>
> My take:  indirect syntax will be around more or less forever.
>

+1 on removing default indirect support, but I hope we can alter the 
current behaviour of 'no indirect' – as written in Neil Bower's Perl 
Quirks document (whic isn't public anymore)

[quote]

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]


-- 

Nicolas Mendoza


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