Skip Menu |
 

This queue is for tickets about the HTML-Tree CPAN distribution.

Report information
The Basics
Id: 37537
Status: open
Priority: 0/
Queue: HTML-Tree

People
Owner: Jeff.Fearn [...] gmail.com
Requestors: colin.fine [...] pace.co.uk
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 3.23
Fixed in: (no value)



Subject: Implementation of as_HTML makes it effectively impossible to subclass
Download (untitled) / with headers
text/plain 1.9k
I want to subclass HTML::Element as HTML::Element::Table, including most of the functionality of Stacy Lacy/Anthony Peacock's HTML::Table in it. I've add HTML::Table as a mixin, and I reckoned all I needed to do was override 'new' and 'as_HTML' (and a couple of other traversal methods that I haven't looked at yet) and add an AUTOLOAD to pass on HTML::Table's methods to it. That worked fine until I tried to output a structure which had HTML::Element::Table objects inside it. I found that my overridden as_HTML table was not being called. Looking at the source, I can see why: as_HTML uses 'traverse' whose comment lovingly explains that it iterates instead of recursing. Furthermore, I can't even override the callbacks, because they are inline (and anyway, are not called as methods). THIS BREAKS OBJECT INHERITANCE because there is nothing there for me to override. If the callbacks were package methods, it would be much messier, but I could override them; but as it is, it won't even work to override as_HTML with a slightly altered copy of itself, as I can't get my version to be called unless I happen to pass it one of my objects as the root of the tree. Note that what I am trying to do is compliant with the NOTES ON SUBCLASSING at the end of the pod: my overridden method does call the superclass method (or did until I tried the approach I mentioned in the previous paragraph). But because this has been done in this way, I can't see any way of bolting the extra functionality on without changing HTML::Element.pm itself. If at least the calls to $c_pre and $_post were changed to $rv - $c_pre->( $this->beforeTraverse(), .... and $rv = $c_post->( $this->afterTraverse(), .... (and the supplied 'beforeTraverse' and 'afterTraverse' just returned their first argument), then at least I could override 'beforeTraverse' to turn my table into element contents. This would mean an extra call, but it's not recursing.
Download (untitled) / with headers
text/plain 236b
In retrospect, I think my comment yesterday was a bit intemperate, and I withdraw some of it: it is not true that it breaks inheritance, rather that there is a severe and undocumented limitation on the sort of subclass you can write.
Download (untitled) / with headers
text/plain 268b
Hi, do you have some sample code to illustrate this? There was a problem with sub classing, see https://rt.cpan.org/Ticket/Display.html?id=36247, which has been patched, but if you supply some code displaying this behaviour I can look in to it further. Cheers, Jeff.
Download (untitled) / with headers
text/plain 525b
On Sat Apr 24 04:21:42 2010, jfearn wrote: Show quoted text
> Hi, do you have some sample code to illustrate this? There was a problem > with sub classing, see https://rt.cpan.org/Ticket/Display.html?id=36247, > which has been patched, but if you supply some code displaying this > behaviour I can look in to it further. > > Cheers, Jeff.
I haven't worked on this for two years, but I'll see if I can come up with something in the next few days. But I don't believe that the other bug of mine that you fixed is relevant to this problem.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.