Closed vickenty closed 4 years ago
Off the ticket I think we agreed with the syntax:
(\*STDOUT)->method()?
No?
We agreed that (\*STDOUT)->method()
makes an unambiguous reference to a file handle. But STDOUT::->method()
still refers to a file handle and not a package, and there is no around that, unfortunately.
I think what we end up with is (\*STDOUT)->method();
:
That means that while STDOUT::->method()
or binmode *STDOUT, 'UTF_8'
or binmode *main::STDOUT, 'UTF-8'
or even binmode *::STDOUT, 'UTF-8'
will all work, by using (\*STDOUT)->method()
, we assure that we know it's a file handle (or will crash at run-time).
Reviewing it now, I want to break this to two different problems:
Foo::Bar->new(); # Foo.pm's Bar() or Foo::Bar's new()?
This can be fixed by the rule that all user-provided subroutines must include parenthesis:
Foo::Bar->new(); # always Foo::Bar's new() - "Foo::Bar" is a literal namespace string
Foo::Bar()->new(); # always Foo's Bar() - Should "Foo" be a namespace or should "Foo::Bar()" be a literal function name?
perl
understands it needs to do:If it's a filehandle, it calls the filehandle. If not, it tries a function or a class name. In either case, who cares. We're not running it, only parsing it.
I think we can close this issue.
A method call on a string is dynamically dispatched. If a filehandle with the given name exists, call will be dispatched to it, otherwise perl will try package name. This does not depend on the method name called, just on the value of the object.
All these are affected:
Behaviour of the code is changed iff a filehandle is assigned to *Foo::Bar, either via call to
open
or via assignment operator:Funnily enough, blessing something into
"Foo::Bar"
undoes the effect:outputs:
It seems that this behaviour is fairly new: under 5.18.4 and 5.20.3 the output is different:
In the end, this behaviour seems to be baked pretty deep into the interpreter and unavoidable using just syntactic changes.