rbc has asked for the wisdom of the Perl Monks concerning the following question:

Hello fellow Monks,

I am getting the error ...

Operation `bool': no method found, argument in overloaded package Vector2D at

... and here's the pertinent code snippets ...

package Vector2D; use strict; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); use overload "-" => \&minus, "+" => \&plus, "*" => \&mult;

... here's the snippet from the script that uses Vector2D ...

sub drawPoly { my @p = @_; #Array of Vector2Ds my $start_point = pop( @p ); while( pop( @p ) ) { $can->create( 'line', $start_point->getx(), $start_point->gety(), $_->getx(), $_->gety()); $start_point = $_; } }
The line number mentioned in the error message
coresponds to this line ...
while( pop( @p ) ) {
... Oh! Wise Monks why has this pestilence befallen me!

Replies are listed 'Best First'.
Re: Operation `bool': no method found, argument in overloaded package Vector2D at
by theorbtwo (Prior) on Jan 24, 2002 at 06:08 UTC

    You've going to kick yourself on this one.

    while(pop(@p)) uses your Vector2D in a boolean context, so it's trying to find a "bool" method to find the boolean value of a Vector2D (IE if it is true or not). If you read the "MAGIC AUTOGENERATION" section of the overload manpage, you'll see that "bool" isn't mentioned there, meaning it can't be autogenerated. (Which makes sense -- all references are natively (or is that nievely?) true.)

    Add a "bool" => \&bool line to your "use overload". (And write the coorosponding method, of course.)

    TACCTGTTTGAGTGTAACAATCATTCGCTCGGTGTATCCATCTTTG ACACAATGAATCTTTGACTCGAACAATCGTTCGGTCGCTCCGACGC
      I see I need to do this in my Vector2D package ...
      use overload "-" => \&minus, "+" => \&plus, "*" => \&mult, "bool" => \&bool; sub bool { my $object = shift; return !undef($obj); }
      ... or I am more clueless than you thought :)

      Thanks!