develooper Front page | perl.perl6.users | Postings from September 2018

Re: extending built-in classes

Thread Previous | Thread Next
From:
Joseph Brenner
Date:
September 25, 2018 04:21
Subject:
Re: extending built-in classes
Message ID:
CAFfgvXVRY_gZ2P7XauDUKBbL3PQCg-dZwytpAVFpcbPRRUg4Dw@mail.gmail.com
Thanks, yes that's one of the first approaches I looked at, but there's
still that extra "does" step before you can say $x.tellall;



On Sat, Sep 22, 2018 at 2:39 PM, Curt Tilmes <curt@tilmes.org> wrote:

> On Sat, Sep 22, 2018 at 5:30 PM Larry Wall <larry@wall.org> wrote:
>
>> On Sat, Sep 22, 2018 at 11:40:13AM -0700, Joseph Brenner wrote:
>> : Sounds good, thanks.
>>
>> Well, yes, *sounds* good.  :-)
>>
>> Monkey patching is allowed but discouraged in Perl 6, because Ruby.
>>
>
> Mixed in roles:
>     https://docs.perl6.org/language/objects#Mixins_of_roles
> may be helpful as well.
>
> You can add a role not just to a class, but to an instance of any other
> class.
>
> my $x = "something";
> say $x.WHAT;
> role MyDebugRole { method mydebugthing { say "mydebugthing" } }
> $x does MyDebugRole;
> say $x.WHAT;
> $x.mydebugthing;
>
> (Str)
> (Str+{MyDebugRole})
> mydebugthing
>
> $x will totally act like it used to, but anywhere you like, now you can
> call .mydebugthing() on it.
>
> Pretty cool.
>
> Curt
>
>

Thread Previous | Thread Next


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