My current Perl Ironman Challenge status is: My Ironman Badge

Thursday, October 7, 2010

Of Modernizing My Own Modules

It is amazing how much bitrot accumulates over the course of a year and a half. And also amazing to see the state of the art move so rapidly.

Dist::Zilla has a break-neck pace of development. While my old dist.ini files still run without issue, so many new and awesomer features have crept into the core. This makes it worth while to revisit your dist.ini files even if changes are minor in your project. AutoPrereqs is smart enough now that only a few MooseX::Declare edge cases are missed. PodWeaver is just plain awesome and if you aren't using it to generate your POD something is wrong. The introduction of the Basic PluginBundle means you have even more fine grained control over your distributions. If you are looking for a basic template of a dist.ini that you can use in your own projects, take a gander at mine (Link to And if you've looked at my documentation for modules and like my POD style, here is my weaver.ini too: (Link to

And while I like modernizing my code, this latest push for several modules wasn't entirely voluntary. Newer perls have broken MooseX::Method::Signatures (and likely Devel::Declare itself). This affects a large chunk of my code as I have grown very accustomed to the idea of having constraints on my methods. The brokenness lies in the parsing itself. Seems it doesn't like there to be a newline between the method declaration and the opening brace. In other words, to avoid this problem you have to use ugly K&R-style braces. So that is what I have been doing for a lot of modules, moving the braces.

But, other modules, it was good-old-fashioned modernization. A new version of POE::Filter::XML was released last night that brings it into the modern era. It was an old module in the sense that the distribution still had distribution artifacts stored in source control. POD was all done by hand and at the bottom of the files. POE::Filter::XML::Handler didn't even have any documentation. I wrote my own god damn accessors. It was ugly.

So I put in the time to make things right. It should be backwards compatible (to an extent). Node was updated to be a proper Moose class (using MooseX::NonMoose::InsideOut) that extends XML::LibXML::Element. This lets us, among other things, override methods and call super() when appropriate (making sure that methods that return Elements actually return Nodes). All of the custom constructors went away. And the logic was greatly simplified by using attributes with native traits. The code simply /looks/ modern.

Next on the chopping block is POE::Component::Jabber. I plan on stripping the functionality down to a mere Role. Also, I am going to remove support for pre-XMPP connections, and server specific connection types for components. I want a mean, lean Role that can be composed cleanly and easily. I also want it to be easily extensible too, so if other enterprising developers /want/ those other connection features, they can implement them and use them without monkey-patching my code.

In other words, POE::Component::Jabber is disappearing and will be replaced with POEx::Role::XMPPClient in the not too distant future.

So don't be afraid of looking back on your modules and vomiting a little in your mouth. It doesn't take /that/ much time to modernize them. That way the next time you want to use something and find a bug in it, you won't cringe when you need to fix it and do a quick release.

No comments:

Post a Comment