Timothy S. Nelson wrote: > On Mon, 23 Feb 2009, Moritz Lenz wrote: > >> Timothy S. Nelson wrote: >>> Another question for everyone - is there some way I can extend a class >>> in such a way that it implements another role? >> >> >> class A does B does C { ... } >> >> where B and C are roles. >> >>> For example, say I have a >>> class Class::A that implements role Role::A, and I want it to also implement >>> Role::B (and I provide an implementation), is there any way I can make it so >>> that *every* instance of Class::A implements Role::B, while doing this from >>> a >>> module that doesn't contain Role::B? >> >> Well, the Role::B must be visible in your scope where you do the >> composition. >> >> Or is your question much more complicated than that, and I am simply to >> dumb to grasp it? > > Maybe I'm too dumb to communicate it. Let me give an example. Say I > do this: > > $file = IO::File.new(...) > > And I want all IO::File objects anywhere in my program (including ones > returned from other libraries) to all be able to .bark(). Can I do something > like this?
Ah, that's called monkey patching, and generally considered rather evil. It might work like this: class IO::File is also does BarkRole { ... } But it's not something you want to advertise anywhere. Cheers, Moritz -- Moritz Lenz http://perlgeek.de/ | http://perl-6.de/ | http://sudokugarden.de/