in reply to Re: De-Overload reference?
in thread De-Overload reference?

What problem are you trying to fix?

It appears you think the following is an example of the problem:

use v5.36; use overload q{%{}} => sub { { foo => 1 } }; sub foo { $_[0]->{foo} } my $x= bless { foo => 2 }, "main"; say $x->foo;

But there's no infinite loop in that program, and the OP asks how to avoid an infinite loop.

[choroba's answer has the same problem, I think.]

I wish the OP would have provided a demo the problem and stated what they were trying to achieve.

Replies are listed 'Best First'.
Re^3: De-Overload reference?
by NERDVANA (Priest) on Apr 17, 2024 at 23:12 UTC
    The code you posted here (without the hash-ref-ref) returns '1', and the code I posted returns '2'.

    In other words, the problem here is that the method 'foo' is accessing the output of the overridden ref operator instead of the true value stored within the object. My example using a hash-ref-ref returns the true value from method foo.

Re^3: De-Overload reference?
by LanX (Saint) on Apr 17, 2024 at 22:15 UTC
    try to access $self->{foo} (to get the 2) INSIDE q{%{}} => sub { { foo => 1 } };

    I even had core dumps while trying to use Data::Dump::pp(\@_)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery