|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
strictly no indirect object syntax?
Do I understand correctly that you would like to disallow
the following syntax as well? my $obj = new Car; If so, can we start by removing it from the documentation in core? Gabor |
|
#2
|
|||
|
|||
|
strictly no indirect object syntax?
Fri, Jul 04, 2008 at 12:05:12PM +0300, Gabor Szabo wrote:
Do I understand correctly that you would like to disallow the following syntax as well? my $obj = new Car; As an option, yes. If so, can we start by removing it from the documentation in core? I thought that chromatic had been busy not that long ago sending patches to remove it. There are still places left? Nicholas Clark |
|
#3
|
|||
|
|||
|
strictly no indirect object syntax?
Fri, 04 Jul 2008, Gabor Szabo wrote:
Do I understand correctly that you would like to disallow the following syntax as well? > my $obj = new Car; Yes, that is indirect object syntax. It means my $obj = Car::->new(); if neither a new() nor a Car() method have been defined (or imported) in the current package. If new() is defined, then it means either my $obj = new(Car()); if Car() is defined too, or my $obj = new("Car"); if it isn't. The latter case would also generate a bareword warning if enabled. While not indirect object syntax, I wonder if we shouldn't also do something about "Car::->new" vs. "Car->new". The latter actually means Car()->new when Car() is defined in the current namespace, so it has a similar gotcha as indirect object syntax: sub Foo::method { print "Foo method\n" } sub Bar::method { print "Bar method\n" } sub Foo { return bless [] ="Bar" } Foo->method; # Prints "Bar method" Foo::->method; # Prints "Foo method" Foo()->method; # Prints "Bar method" I think the "Foo->method" call should generate a warning that it is being resolved as "Foo()->method", just like use warnings; sub die {print "my die\n"} die; warns with Ambiguous call resolved as CRE::die(), qualify as such or use & Cheers, -Jan |
|
#4
|
|||
|
|||
|
strictly no indirect object syntax?
Fri, 04 Jul 2008, Eric Wilhelm wrote:
# from Jan Dubois # on Friday 04 July 2008 08:50: >* Foo->method; * * # Prints "Bar method" >* Foo::->method; * # Prints "Foo method" >* Foo()->method; * # Prints "Bar method" > >I think the "Foo->method" call should generate a warning that it is >being resolved as "Foo()->method", just like If so, how would you disable it on a per-bareword basis so that aliased.pm still works? sub Foo () :alias {'Bar'} Note that this should only warn if %bar:: isn't empty (at compiletime), because otherwise it isn't ambiguous. If you do have a regular %Bar:: namespace *and* want to alias another package name to 'Bar', then you can always disable the warnings with no warnings 'ambiguous'; just the same way you can disable the current warnings about resolving ambiguous function calls to their CRE:: version can be suppressed. Cheers, -Jan |
|
#5
|
|||
|
|||
|
strictly no indirect object syntax?
Friday 04 July 2008 06:56:54 Nicholas Clark wrote:
Fri, Jul 04, 2008 at 12:05:12PM +0300, Gabor Szabo wrote: Do I understand correctly that you would like to disallow the following syntax as well? > my $obj = new Car; > As an option, yes. > If so, can we start by removing it from the documentation in core? > I thought that chromatic had been busy not that long ago sending patches to remove it. There are still places left? At least one author of a dual-lived module objected, and I gave up. -- c |
|
#6
|
|||
|
|||
|
strictly no indirect object syntax?
Fri, Jul 04, 2008 at 08:50:00AM -0700, Jan Dubois wrote:
While not indirect object syntax, I wonder if we shouldn't also do something about "Car::->new" vs. "Car->new". The latter actually means Car()->new when Car() is defined in the current namespace, so it has a similar gotcha as indirect object syntax: sub Foo::method { print "Foo method\n" } sub Bar::method { print "Bar method\n" } sub Foo { return bless [] ="Bar" } Foo->method; # Prints "Bar method" Foo::->method; # Prints "Foo method" Foo()->method; # Prints "Bar method" Yes, but the commonly followed standard is that subroutine names are in all lowercase. While I agree that in theory the gotcha is similar, in practise, it will be far less of an issue. I think the "Foo->method" call should generate a warning that it is being resolved as "Foo()->method", just like Well, only if it *is* resolved to "Foo()->method", that is, only warn if there's an actual Foo() subroutine that will be called. the warning will trigger too many false positives to be of any use. Abigail |
![]() |
| Viewing: Web Development Archives > Mailing Lists > Perl > strictly no indirect object syntax? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|