Data::Compare 0.06 released

drhyde on 2004-01-07T09:25:00

Last night I released Data::Compare 0.06. It's functionally the same as the previous release, but the special-case support for comparing Scalar::Properties objects has been moved into a plugin.

Supporting plugins was Jim Cromie's idea. He was even good enough to send a nice big patch. I ended up not using his patch and writing my own version, for various reasons, but he deserves a great deal of credit for the idea.

The way I've done plugins is, I think, really nifty. We use File::Find::Rule to find any Data::Compare::Plugins::* module on the system, and require it. Because require returns the value from evaluating the code, we make use of that, and instead of just evaluating to 1 like most modules do, plugins must evaluate to a data structure which describes what the plugin can compare and how. That is squirreled away in a hash for easy access later.

Then, whenever we come to compare two structures, we first check to see if there is a hash entry for that pair of data types and if there is, do whatever the plugin says. If there isn't, we try to compare the underlying data structures.

Plugins are useful in two circumstances that I can see:

  1. when your data type has overloaded operators like stringify, numify, and comparison - you can now provide code so that Data::Compare can delve into their guts and *really* compare them;
  2. you want non-equal structures to compare equal. The plugin for Scalar::Properties is an excellent example. I decided that a true scalar and a Scalar::Properties should be treated as being the same if they stringify/numify the same, but that comparing two S::Ps should only succeed if both their values and all their properties match.


And then this morning, the first thing I did was spot a documentation bug in the new version. Oops.

[Update] I spotted another oopsie too, where it might try to load the same plugin twice, and hence spit out errors about redefined subroutines and stuff. Both fixed in 0.07 :-)