stevan / p5-mop-redux

A(nother) MOP for Perl 5
139 stars 36 forks source link

should we still have attribute conflicts in roles? #113

Closed doy closed 10 years ago

doy commented 10 years ago

Now that attributes are class-private, does it make sense for them to still conflict during role application?

doy commented 10 years ago

I guess the main thing here would be figuring out what to do with constructor parameters if there was no conflict.

doy commented 10 years ago

Then again, we already have this issue with inheritance - there is currently no conflict for class Foo { has $!foo } class Bar extends Foo { has $!foo }. Is that a problem?

doy commented 10 years ago

Maybe what we need is to have a way to specify init_args for attributes, and then only conflict on methods and init_args, not attributes themselves.

stevan commented 10 years ago

hmm, not sure I like that much

doy commented 10 years ago
$ perl6 -e'role A { has $!foo; method a { $!foo } }; role B { has $!foo; method b { $!foo } }; class C does A does B { }; my $c = C.new; say $c.a; say $c.b'
===SORRY!===
Attribute '$!foo' conflicts in role composition

So, I guess just leaving it as it is would be fine too. I'm not really sure I like that, since it breaks encapsulation a bit (private attributes really shouldn't be visible as part of the public API like that), but I can't really think of a better solution that doesn't end up even uglier.