Question below after Dave's reply. -----Original Message----- From: Dave Rolsky [mailto:auta...@urth.org] Sent: Thursday, July 08, 2010 6:18 PM To: Macdonald, John (Enterprise Data) Subject: Re: removing a role in Moose
Please email moose@perl.org, or join us in IRC @ irc.perl.org/#moose. Thanks, -dave On Thu, 8 Jul 2010, Macdonald, John wrote: > I see the doc about apply_all_roles to apply a role to an instance, but is > there a way of removing or replacing a role? > > I'm setting up a hierarchical data structure, with a class that defines the > general aspects of the data structure and sub-classes for the component > sub-structures. There will be methods for traversing the hierarchy. > > I want to have it possible for a particular node in the structure be in > various states that can be altered dynamically. Here's an example of the > sort of thing I want to do: > > my $tree = Class->create_from_XML( file=>$file, duration=>$duration ); > > The duration parameter would be one of qw( fill lazy stream ). > > > - With 'fill', the XML file would be read and parsed and the entire > structure created. > > > - With 'lazy' or 'stream', the XML file would be opened and read far > enough to create the top level class element only. > > > The class would have methods for traversing the data structure. When a node > was created with 'lazy' or 'stream', it would not actually be complete > initially, but the first traversal method applied to it would cause the next > level of nodes to be created. (For 'stream', when the traversal is finished > with a particular node, the node is no longer retained.) > > What I was thinking of doing was to have traversal roles to define the > traversal methods, and have a traverse_from_XML role (and similar roles for > creation from other sources) that gets applied to the node initially, but > then when the traversal actually hits the node, the methods in this role > would read further into the XML input file, and then change the node so that > it no longer had the traverse_from_XML role, but instead a > traverse_loaded_node role would be applied to it. When the node traversal > was complete, the child contents would be deleted and the node would be > re-roled into a traverse_completed role that failed if a further traversal > was attempted before the parent node had finished being traversed. > > However, when I read about method conflicts, I suspect that this whole > approach is not going to work and that I need to accomplish my goal in a > different way. > > Do you have any suggestions? > > John Macdonald > Morgan Stanley | Technology & Data > 75 Queen Street | Suite 5400 > Montreal, QC H3C2N6 > Phone: +1 514 687-2615 > john-421.macdon...@morganstanley.com<mailto:john-421.macdon...@morganstanley.com> > > -------------------------------------------------------------------------- > NOTICE: If received in error, please destroy, and notify sender. Sender does > not intend to waive confidentiality or privilege. Use of this email is > prohibited when received in error. We may monitor and store emails to the > extent permitted by applicable law. > /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/ -------------------------------------------------------------------------- NOTICE: If received in error, please destroy, and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error. We may monitor and store emails to the extent permitted by applicable law.