Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Sounds like Data::Compare is broken. A quick peek at the source turned up exactly the type of broken code that I expected to see:

if(ref($requires) ne 'ARRAY') {

So just fix Data::Compare. The fixes would probably be quite simple. The best fix is to change such things to:

if( ! eval { @$requires; 1 } ) { # Can't be used as an array re +f

It is fine to use ref as a Boolean test. Any other uses of ref I simply can't recommend.

Note that the above trick doesn't work for CODE references so you have to resort to one of the second-best methods. I'd use the following:

*isa= UNIVERSAL::isa; #... if( isa( $ref, "CODE" ) ) {

Note that this test can fail in the case of overloaded objects that want to pretend to be CODE references but that didn't bother to push @ISA, "CODE"; in order to declare this intention (which seems a perfectly reasonable restriction to me). chromatic would surely cringe and moan upon seeing such code because surely $ref->isa("CODE") is what should be used (except, of course, that it is likely to die in many cases). eval { $ref->isa("CODE") } might be a possible alternative but I thought it had its own drawbacks even though I can't recall what they were. My preferred method can also produce false positives if somebody intentionally lies via push @ISA, "CODE"; which I also consider to be a perfectly reasonable feature (which can even be useful when writing unit tests, for example).

Looking at the code further, I see one spot that would be somewhat complex to fix because it assumes that a reference can only be of one type, which is not the case. But it would also simplify other parts of the code, because there would not have to be special code for looking under the covers of blessed references.

Actually, perhaps it would be best to leave the plug-in handling alone, despite the flawed assumptions present there. Replacing the flawed assumptions with proper handling when considering handlers for specific classes of objects would be quite complex and you don't need to fix plug-in support in order to fix the basic flaw in the module; thus making it work fine on DBM::Deep results.

Then the module becomes quite easy to fix (and the fixes still simplify some parts). The best route would probably be to write the following tiny helpers:

sub isArray { eval { @{$_[0]}; 1 } } sub isHash { eval { %{$_[0]}; 1 } } sub isScalar { eval { ${$_[0]}; 1 } } sub isCode { UNIVERSAL::isa( $_[0], "CODE" ) }

And then the less-tiny helper:

sub getCommonRefType { my( $ref1, $ref2 )= @_; return "ARRAY" if isArray($ref1) && isArray($ref2); return "HASH" if isHash($ref1) && isHash($ref2); return "SCALAR" if isScalar($ref1) && isScalar($ref2); return ""; }

- tye        


In reply to Re^5: Is this DBM::Deep behavior, or something with tie/bless? (ref) by tye
in thread Is this DBM::Deep behavior, or something with tie/bless? by romandas

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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> <u> <ul>
  • 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 intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-23 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found