develooper Front page | perl.perl6.language | Postings from March 2005

Re: MMD as an object.

Thread Previous
From:
Thomas Sandlaß
Date:
March 9, 2005 09:21
Subject:
Re: MMD as an object.
Message ID:
422F308D.3070604@orthogon.com
Luke Palmer wrote:
> Keep in mind that the two following definitions are equivalent:
> 
>     class A { method foo () {...} }
>     multi sub foo (A $a) {...}

Except for attribute access, I think.
For public attrs the accessor is not used and private ones are available:

class A
{
    has $.pub = "pub";
    has $:priv = "priv";
    method foo ()
    {
       say "pub = $.pub";
       say "priv = $:priv";
    }
}

multi sub foo( A $a )
{
    say "pub = $a.pub()";
}

Another subtlety is that the method call syntax prefers single dispatch:

my $obj = A.new;

$obj.foo();
foo( $obj );


> I think stuffing a method into a multi sub should be just fine.

Me too. The above is irrelevant for the call site.

MfG
-- 
TSa (Thomas Sandlaß)



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About