Skip Menu |

This queue is for tickets about the Class-Trait CPAN distribution.

Report information
The Basics
Id: 22815
Status: resolved
Priority: 0/
Queue: Class-Trait

People
Owner: ovid [...] cpan.org
Requestors: drrho [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: 0.22
Fixed in: (no value)



Subject: inheriting traits?
Not sure whether this is a bug, probably more a wishlist or misunderstanding. Probably I am a bit mislead by http://www.oreillynet.com/onlamp/blog/2006/08/perl_module_review_classtrait.html I wonder why it is not possible to inherit traits: package T1; use Class::Trait 'base'; sub t1 { return "1"; } package T2; use base 'T1'; sub t2 { return "2"; } 1; package Mine; use Class::Trait qw(T2); sub new { return bless {}, shift; } 1; $tt = new Mine; warn "oops" unless $tt->does ('T1'); warn $tt->t1; #---- Thanks for this package. \rho
Hi, Sorry it took me so long to respond. On Sun Nov 05 03:27:41 2006, DRRHO wrote: Show quoted text
> I wonder why it is not possible to inherit traits:
You can't inherit the traits because traits, by design, are to be composed rather than inherited. The following code will do what you want. First, here's T1: package T1; use strict; use warnings; use Class::Trait 'base'; sub t1 { return "1"; } 1; Now let's look at T2: package T2; use strict; use warnings; use Class::Trait 'base'; use Class::Trait 'T1'; sub t2 { return "2"; } 1; It declares Class::Trait to be its base class and it uses the T1 trait. That's how traits are assembled together. Your code for package 'Mine' was perfect and will now do exactly what you expect. Cheers, Ovid
CC: DRRHO [...] cpan.org
Subject: Re: [rt.cpan.org #22815] inheriting traits?
Date: Wed, 22 Nov 2006 07:25:13 +1000
To: via RT <bug-Class-Trait [...] rt.cpan.org>
From: Robert Barta <rho [...] bigpond.net.au>
On Tue, Nov 21, 2006 at 04:05:13PM -0500, via RT wrote: Show quoted text
Show quoted text
> Sorry it took me so long to respond.
No worries. Show quoted text
> use Class::Trait 'base'; > use Class::Trait 'T1';
Aahhh. I never grokked/realized that traits "can have traits" as well. Nice. Thx again! \rho
Reclosing ticket. Please do not respond to this email as doing so will reopen the ticket. Not sure why things were configured in such a way that I have to reply to you and ask you to ignore my message :( Cheers, Ovid