Am 17.06.2009 um 18:52 schrieb Stevan Little:
Rolf,
Once the the role is applied to the PW::Base it cannot be unapplied
or replaced, it has been composed into PW::Base for good.
I think perhaps you don't want to apply PW::RoleA to PW::Base, but
perhaps move that higher up the inheritance chain so it wont
conflict with the 'PW::Site::Xy::RoleA'.
Not much more advice I can give beyond that as I am not sure what
your problem domain actually is.
- Stevan
What I want do is to write a price calculation for different products.
Each product has its own "rules" how a price is calculated.
The products are part of different webshops for different customers
who may want to be able, to modify
these rules.
So my first idea was to have a base class Product with an (empty)
method "calc" and subclasses for each product (I.e. Product::A,
Product::B,...). The rules for calculating the price are "rules",
and each product subclass uses the rules it needs, so Product A may
have
with ('RuleA','RuleB', 'RuleC'),
ProductB has
with ('RuleA','RuleC', 'RuleD'),
and so on. The rules are independent, so they define an "after calc"
sub and get called automatically from product calc.
So far it works.
Now, a customer buying our shop may want to override RuleA (or even
not use a Rule from the base class at all) for ProductA.
It tried this with writing a subclass for Product::A as
Cutomer::Xy::Prouduct::A
extends Product::A
with 'Customer::Xy::RuleA'
where Customer::Xy::RuleA should exclude RuleA (end replace it).
with the result seen in th old mail.
Now, the only solution I see would be to write custom specific
calculation rules by making a subclass not from Product::A but from
"Product" and define all rule there. But then I can't inherit all
other methods from Product::A or I have to put them all in rules.
Any other idea ?
On Jun 17, 2009, at 12:47 PM, Rolf Schaufelberger wrote:
Hi,
I would like to be able to replace a role in subclass :
When I have a class and a Role
package PW::Base ;
with 'PW::RoleA';
...
;
==========
package PW::RoleA;
..
after calc => sub {.. };
==========
AND and subclass of PW::Base where I want to have another calc
method,
so I have another Role for it:
package PW::Site::Xy::Base;
extends PW::Base;
with 'PW::Site::Xy::RoleA'
...
AND
PW::Site::Xy::RoleA
excludes 'PW::RoleA';
..
after calc => sub {.. };
==========
now I get the error:
The class PW::Site::Xy::Base does the excluded role 'PW::RoleA'
So what am I doing wrong ?
Rolf Schaufelberger
Mit freundlichen Grüßen
Rolf Schaufelberger
plusW GmbH
Stuttgarter Str. 26 Tel. 07183 30 21 36
73635 Rudersberg Fax 07183 30 21 85
www.plusw.de
www.mypixler.com
www.calendrino.de