http://qs321.pair.com?node_id=390232


in reply to proxying overloads: returns seem to lie

Your problem is context.

print operates in interpolative context so $capsule returns It's a widget! but ne operates in boolean context so $capsule returns something like Object::Capsule=SCALAR(0x1234567).

I ran three tests:

Here's the output using Perl 5.6, Cygwin and Win98:

[ ~/tmp ] $ perl overload_context # capsule overload eval-ing : ${$_[0]} eq $_[1] Segmentation fault (core dumped) [ ~/tmp ] $ perl overload_context # result of comparison: true # result of comparison: false # -- bytes of returned strings -- # 73 116 39 115 32 97 32 119 105 100 103 101 116 33 # 73 116 39 115 32 97 32 119 105 100 103 101 116 33 --(Test::More stuff below this point)-- [ ~/tmp ] $ perl overload_context # result of comparison: true # result of comparison: false # -- bytes of returned strings -- # 73 116 39 115 32 97 32 119 105 100 103 101 116 33 # 73 116 39 115 32 97 32 119 105 100 103 101 116 33 --(Test::More stuff below this point)-- [ ~/tmp ] $

Regards,

PN5

Replies are listed 'Best First'.
Re^2: proxying overloads: returns seem to lie
by rjbs (Pilgrim) on Sep 11, 2004 at 14:26 UTC
    Huh! Well, it's good that I can now make the code work, although it starts to suggest to me that I'm going to need to write more explicit overloading for the Capsule class to make everything work correctly. Meanwhile, I'm not sure, given your explanation, why this works normally:
    my $result = $widget eq "It's a widget!"; print "# result of comparison: ", ($result?'true':'false'), "\n";
    I suppose there's some context change going on in the capsule's overload nomethod, but I'm not clear on what it is.

    Is there a simple tool I could use to see these context changes? I don't think it's the debugger, but maybe it's got voodoo I don't know about.
    rjbs

      Glad you got your code working.

      I'm not sure about tools for this: investigation of the CPAN Module: Want may prove fruitful.

      Regards,

      PN5