I'll chime in, as I'm the one who initially raised the idea : ) I'll start with a use-case: my initial motivation for having is_deeply handle coderefs came up while building certain unit tests for a rewrite of DBD::Mock. Several of the worker functions return complex data structures -- which may contain coderefs -- and I'd like to simply hand the whole lot off to is_deeply and have the work done for me.
My inital strategy for implementing this was a two-tiered approach. First, compare the references; if they're the same, return true, go no futher. If they differ, however, say if anonymous subs were thrown into the mix, then use B::Deparse to decompile both subs, comparing their textual representations. My initial quick-glance at B::Deparse's documentation mentions something about perl optimising certain constants away, which could well throw a spanner into the works. Storable uses B::Deparse when serialising coderefs, though, so I'm certain there's a way around this. Collin Winter On 6/25/05, Michael G Schwern <[EMAIL PROTECTED]> wrote: > Currently, throwing is_deeply() a code ref causes it to barf. > > perl -MTest::More -wle 'print is_deeply sub {}, sub {}' > WHOA! No type in _deep_check > This should never happen! Please contact the author immediately! > # Looks like your test died before it could output anything. > > > is_deeply() doesn't know what to do with code refs. What should it do? > > What it *shouldn't* do is what Test.pm does, namely execute the code ref and > compare the values returned. It would just compare the refernces. > > This much is obvious, this should pass: > > is_deeply \&foo, \&foo; > > The same code ref is being compared. But here's the tricky part. > > is_deeply sub { 42 }, sub { 42 }; > > Does that pass? ie. Are we just comparing the reference value or should > is_deeply() decompile the subroutine and see if they contain the same code? > (Technical considerations aside, for the moment). > > Given that is_deeply() considers these to be equivalent: > > is_deeply [ 42 ], [ 42 ]; > > I think comparing the decompiled source code is consistent, but is it > useful? Anyone have use cases for this? > > > -- > Michael G Schwern [EMAIL PROTECTED] http://www.pobox.com/~schwern > Don't try the paranormal until you know what's normal. > -- "Lords and Ladies" by Terry Prachett >