
perl.p5p at rjbs
May 16, 2008, 2:00 PM
Post #6 of 6
(112 views)
Permalink
|
|
Re: method call overloading: more better tests
[In reply to]
|
|
* David Nicol <davidnicol[at]gmail.com> [2008-05-16T16:19:03] > On Fri, May 16, 2008 at 10:30 AM, Ricardo SIGNES > <perl.p5p[at]rjbs.manxome.org> wrote: > > > my $x = $instance->new; > > # Fatal: no instance method 'new' on Instance(ParentClass) > > > what's wrong with good old-fashioned > > *{ref($instance).'::new'} = sub { die "new invoked on protected > superclass" } Well: (a) it's ugly, confusing and requires turning off strictures (b) it means that no new Instances can be created (c) it doesn't actually do the same thing at all The sample code shows a way to create classes and instances that look like normal invocants but use different dispatching rules. The example line I cited above shows that you could make an instance simply not HAVE a new method. Your murder of Instance::new would be pointless in the context of the example, because it could not be called. Outside the context of the example, Instance would be both the "instance class" and the "class class," meaning that now you can't construct new Instance objects. If Class were to return objects blessed into Instance, then you can still call Instance->instance_method, which is back to FAIL. So, in answer to your question: everything. -- rjbs
|