It’s just data

Smooth Migration to XML::SAXParser's new Callbacks

libxml's XML::SAXParser has been changed in the Development Release to use callbacks.  If you want to code to the new interface yet continue to work with the released interface, the following can be added to your code:

if !XML::SaxParser.const_defined?(:Callbacks)
  # shim to upgrade libxml 0.3.8.4 to the 0.5.2.0 interface
  class XML::SaxParser
    module Callbacks
    end

    def callbacks= callback
      callback.methods.grep(/^on_/).each do |method|
        send(method) { |*args| callback.send method, *args }
      end
    end
  end
end

This code is now part of Mars.  Props to Scott Bronson.


Smooth Migration to XML::SAXParser’s new Callbacks

Thank you for not selling this as a reason for why dynamic languages are better ... :-)

Posted by Matthias at

Add your comment