FAQ
I've written one more set of overloaded-method-invocation tests, attached with
a slightly improved version of the classless-root test.

The new tests is a class-based scheme. In my vision of using overloaded
->method, the package-based old-style classes become places to put behavior
about how the "real" class works. They are, in effect, simple metaclasses.
The new test has two of these: Class and Instance. They differ primarily in
their universal methods and in how they dispatch.

I think that these two tests are really exciting! They show that over the
course of a short bus ride, a middling Perl programmer like me can implement
two useful (if woefully trivial) new object systems. Unfortunately, the needed
syntax currently is dreadful. With -> overloading, custom, purpose-optimized
object systems can be made easily, with client code that looks just like good
ol' fashioned Perl.

my $x = $instance->new;
# Fatal: no instance method 'new' on Instance(ParentClass)

my $x = $instance->class->new;
# okay!

It cannot be resisted!

--
rjbs

Search Discussions

  • Rafael Garcia-Suarez at May 16, 2008 at 3:42 pm
    2008/5/16 Ricardo SIGNES <perl.p5p@rjbs.manxome.org>:
    I think that these two tests are really exciting! They show that over the
    course of a short bus ride, a middling Perl programmer like me can implement
    two useful (if woefully trivial) new object systems. Unfortunately, the needed
    syntax currently is dreadful. With -> overloading, custom, purpose-optimized
    object systems can be made easily, with client code that looks just like good
    ol' fashioned Perl.
    Your way of abstracting out method calls, or whatever, makes my head
    hurt. But that looks cool !! now find someone to write the code ! :)
  • Ricardo SIGNES at May 16, 2008 at 4:39 pm
    * Rafael Garcia-Suarez [2008-05-16T11:42:12]
    2008/5/16 Ricardo SIGNES <perl.p5p@rjbs.manxome.org>:
    I think that these two tests are really exciting! They show that over the
    course of a short bus ride, a middling Perl programmer like me can
    implement two useful (if woefully trivial) new object systems.
    Unfortunately, the needed syntax currently is dreadful. With ->
    overloading, custom, purpose-optimized object systems can be made easily,
    with client code that looks just like good ol' fashioned Perl.
    Your way of abstracting out method calls, or whatever, makes my head
    hurt. But that looks cool !! now find someone to write the code ! :)
    I needed a way to show that it all worked with the underlying implementation
    AND test that the sugar DTRT without needing to rewrite crap over and over, but
    yeah. It's also sad that the tests for the sugar hide how sweet it is.

    Someone has already said he'd have a look at making tests pass. That would be
    sweet!

    --
    rjbs
  • David Nicol at May 16, 2008 at 8:19 pm

    On Fri, May 16, 2008 at 10:30 AM, Ricardo SIGNES 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" }

    ?
  • Demerphq at May 16, 2008 at 8:22 pm

    2008/5/16 David Nicol <davidnicol@gmail.com>:
    On Fri, May 16, 2008 at 10:30 AM, Ricardo SIGNES
    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" }

    ?
    Besides that its ugly and hard to explain to a newbie you mean?

    yves


    --
    perl -Mre=debug -e "/just|another|perl|hacker/"
  • Ricardo SIGNES at May 16, 2008 at 9:01 pm
    * David Nicol [2008-05-16T16:19:03]
    On Fri, May 16, 2008 at 10:30 AM, Ricardo SIGNES
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedMay 16, '08 at 3:31p
activeMay 16, '08 at 9:01p
posts6
users4
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase