Thursday was what I refer to as a "bad hair day for coding." After completing a beta version of the mt-rssfeed plugin and its underlying liberal parser, I began testing myself and was in for a rude, time-consuming surprise.
I made the fateful decision to support XML::Parser::Lite as a fallback option to its bigger brother XML::Parser. Lurking in the MoveableType support boards I noted a significant number of users work with hosts that do not have XML::Parser and do not allow users to compile software (the module is a wrapper to Expat that uses C) or simply do not have the expertise to do it themselves. XML::Parser::Lite is an all Perl solution that uses a mega regular expression routine called REX. Lite does not support namespaces though, so I had to reverse engineer Expat's namespaces handling and put it into my liberal parser. While time consuming and in a sense reinventing of the wheel, it was interesting educational work that I thought was well worth the effort to make this code more useful to all MoveableType users. The rude surprise came Thursday when I began testing against Lite producing a "Segmentation Fault" -- Perl's version of a core dump or general protection fault. I spent all day Thursday trying to figure out why my code performed flawlessly with Expat and completely crashed with Lite. It ends up Lite uses some experimental regular expression code (the ?{ } construct) to call the event handlers you have registered. If you have any regular expressions in your handlers (as I did to support namespaces) it will crash Perl. This wasn't documented unless you examine the code. (Insert your favorite expletives here.) I spent Thursday evening and Friday weighing my options and reworking the code to accommodate this quirk. What's noteworthy is that the original REX code does not use this experimental construct. The question begs to be asked is there a better and safer way to implement such a parser? I think there is with some thought that I don't have just yet. I assume the module was coded this way for better performance, however convenience and simplicity are the reasons for using Lite (for me at least) that the use of these constructs seem to undermine. Furthermore it makes inserting namespace handling code in Lite, something I've considered after all the trouble I've gone through, difficult perhaps impossible. Another option to consider is XML::SAX::PurePerl.
Some much to do and so little time.
For MoveableType users waiting for the rewritten and substantially enhanced version of mt-rssfeed Wednesday is the day -- assuming I don't find another surprise.

Leave a comment