develooper Front page | perl.perl6.language | Postings from March 2009

Recursive Runtime Role Reapplication Really Rebounds

Thread Next
March 8, 2009 08:24
Recursive Runtime Role Reapplication Really Rebounds
Message ID:

(OK, the subject sucked, but I tried :)

From S14:

  You can, however, say
      $fido does Sentry;
      $fido does Tricks;
      $fido does TailChasing;
      $fido does Scratch;
  Unlike the compile-time role composition, each of these layers
  on a new mixin with a new level of inheritance, creating a new 
  anonymous class for dear old Fido, so that a .chase method from 
  TailChasing hides a .chase method from Sentry.

Recently I reported a bug in Moose's runtime role application:

The problem was very hard to track down because I was effectively doing something like this:

  $object->meta->apply('Some::Role') while 1;

(The reality is that we had a singleton with a role applied to it multiple times).

Eventually, the code broke and threw a bunch of weird "recursive inheritance" warnings due to multiple anonymous classes being applied to the object.  This was *real fun* to debug, but I can imagine a scenario for this being natural:

Your REST interface returns XML, but sometimes someone wants YAML.  So you have:

  $resultset does Role::Serializable::XML

But sometimes:

  $resultset does Role::Serializable::YAML

Since you cache resultsets if they've not changed, you could easily have the XML and YAML roles getting reapplied at runtime multiple times.  

I don't see anything in the spec addressing this.  Aside from "don't do that", is this something which can be addressed in perl instead of Perl?

Buy the book         -
Tech blog            -
Twitter              -
Official Perl 6 Wiki -

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About