in reply to Re^2: A little overloading conundrum
in thread A little overloading conundrum

If you are working around it in the caller, this is clearer, if not as efficient:
my $n2 = -($A_obj - $B_obj);

Replies are listed 'Best First'.
Re^4: A little overloading conundrum
by syphilis (Archbishop) on Mar 08, 2026 at 04:38 UTC
    If you are working around it in the caller...

    Apologies - I should have explicitly stated that "working around it in the caller" is not a solution.
    It's imperative that, wrt the given pseudo-example, my $n2 = $B_obj - $A_obj; return a module A object with a value of -10.
    Hence my agreement with sw1's labelling of both his and my alterations to the caller as being "not practical".

    If module B did not overload the '-' operator then, AIUI, my $n2 = $B_obj - $A_obj; would invoke module A's overloading of that operator - which is exactly what I want.
    I was hoping there might have been some way of triggering that same behaviour when module B does overload that operator .... but it seems that's not the case.

    Cheers,
    Rob