Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Shlomi Fish (918)

Shlomi Fish
AOL IM: ShlomiFish (Add Buddy, Send Message)
Yahoo! ID: shlomif2 (Add User, Send Message)

I'm a hacker of Perl, C, Shell, and occasionally other languages. Perl is my favourite language by far. I'm a member of the Israeli Perl Mongers, and contribute to and advocate open-source technologies. Technorati Profile []

Journal of Shlomi Fish (918)

Friday February 02, 2007
09:25 AM

XML::RSS Update: Refactoring

[ #32305 ]

After we got XML::RSS to a stage where it has 100% test coverage, it was possible to refactor things with more assurance that we don't break anything. So I did exactly that and gave XML::RSS a facelift.

Among the things I did were:

  1. Extracted many methods, including some that appeared several times.
  2. Instead of the $output .= "<tag>"... pattern, converted everything to append to a buffer that is stored in an object property, and using $self->_out($mystring) calls and many methods on top of it for outputting entire tags, and higher-level abstractions.
  3. Made sure all tags end with one newline and not two as was the case for some of them. This enabled an easier refactoring.
  4. Got rid of the AUTOLOAD method, which was only used for accessors, and instead wrote several such accessors manually using the _handle_accessor() method. This should eliminate many obscure errors in using XML::RSS and also make things somewhat faster.
  5. Converted many direct member retrievals (->{'channel'}...) to their accessor versions.
  6. Made many methods common to all RSS versions with the differences encapsulated in checks for the current _rss_out_version() object parameter, which is assigned at the beginning of the rendering process.
  7. Converted several if-elsif-else-constructs to dispatches.

Meanwhile, Ask ran perltidy on the "lib/XML/" module itself to make its style more consistent. (Which I may have broken somewhat since then, but since the perltidy configuration file is in the repository, we can run it again.) With all of these changes, the code looks much better, than it used to before I started working on it.

I still have some changes I'd like to make in the pipe, like converting each RSS output version into a class and using the convert conditional to polymorphism refactoring, and making the XML parsing functions accept the XML::RSS object handle as an argument, so we can use true methods there instead of just functions inside the same namespace. I'm still waiting for Ask to approve these changes as he didn't reply to my email about it yet.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.