Things like the Test::More::is_deeply function or the useful Test::Deep module would be great, but they're tied to Perl's testing framework.
You could just extract the relevant code from is_deeply and provide a "deep_references" option in the constructor as to whether references should be compared by their refaddr or by their contents. For this, you'll need to keep a copy of the references, too, hashed on their refaddrs to be able to retrieve them for comparison. (I think you'll want a regular reference, not weak one -- and the semantic will then be that storing something under a reference increments the refcount for that reference.)
The other way to go is more like tye's suggestion around the hashing function, so if you want deep references, you freeze their contents into a string and hash on that.
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
Are you posting in the right place? Check out Where do I post X? to know for sure.
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
Want more info? How to link
or How to display code and escape characters
are good places to start.