in reply to overloading '0+'

0+ is used whenever the variable is used as a number. 0+ is the conversion to a number not just to an integer. So in the line;
my $int = int($soldier1);
The call to int is one call to truncate and then the assignment is the other.

If you don't have bool overloaded and 0+ is overloaded then, 0+ will be used in a boolean context, which is why truncate is being called in this code;

$soldier ? 1: 0;

See overload for the all the gory details. (perldoc overload) The sections titled "Boolean, string and numeric conversion" and "Transcendental functions" answer your questions.

Replies are listed 'Best First'.
Re^2: overloading '0+'
by ikegami (Patriarch) on Sep 02, 2007 at 22:12 UTC

    and then the assignment is the other.

    No. Assignments don't trigger 0+, and the result of the call to int is not an object, so overload doesn't apply to the assignment. I verified this by removing the assignment.

      Your right. My bad. How about this for an explanation;

      The argument to int is evaluated in numeric context, which calls truncate. Then when there isn't an overload for int, 0+ is used, which calls truncate again ???