Hi Diab- I haven't done much with subclassing from PDL but I have noted some warts as in PDL::Complex.
For the PDL::NextGen work I would like to have an approach that is interoperable with Moo[se] and possibly other OO frameworks. One thought was to make PDL-ness a Role rather than a class as that seemed it might work better to factor out the PDL computations as a cross-cutting concern. Regarding the PDLx::DetachedOject approach, I'm a bit confused. Is there a reason that the PDL attribute was not sufficient with an appropriate initialize()? The example initialize doesn't appear to do any of the subclass initialization/construction at all. How do you handle the case of the results of a PDL operation on a MyPDL being a PDL and not a MyPDL? Without knowing the details of the MyPDL I can't really see what the problem with initialize() would be. However, sight unseen, maybe using a the PDL attribute as a code ref + closure might be a way to work around the difficulty? I definitely would like to see PDL and PDL::NextGen be interoperable with the Moo[se] universe as that would be a direction that could be applicable to perl6 as well. --Chris On 10/21/2016 17:37, Diab Jerius wrote: > I've been having lots of fun lately creating complex classes which > inherit from PDL. Unfortunately, when PDL creates objects on the fly, > e.g. when it needs to store the result of an operation: > > $mpdl = MyPDL->new; > $npdl = $mpdl + 1; # $npdl will be of class MyPDL > > it can't pass along any additional parameters to the constructer. > This can cause a problem if the object's attributes cannot be given > default values, as the constructed object will be incomplete. > > For example, I've got some polymorphic code which handles MyPDL's > differently from PDLs. In the above example, when passed $npdl it > thinks it's a MyPDL object, but required attributes aren't set, and > things explode. > > Things would be easier if $npdl were constructed as a plain piddle. > The actual code to do this isn't complicated, but it may not be > obvious how to apply it when using one of the class frameworks (such > as Moo, Class::Tiny, etc.), so I've whipped up a simple distribution, > PDLx::DetachedObject. > > For now it's just up at github & bitbucket: > > https://github.com/djerius/PDLx-DetachedObject > > https://bitbucket.org/djerius/pdlx-detachedobject > > The module includes a more detailed writeup of what's going on; I'd > appreciate comments and corrections! > > Thanks, > Diab > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, SlashDot.org! http://sdm.link/slashdot > _______________________________________________ > pdl-devel mailing list > pdl-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/pdl-devel ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ pdl-devel mailing list pdl-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pdl-devel