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

I have some code that causes the following error:

Can't resolve method "name" overloading """" in package "overload" at <file> line <line>.

(The code referenced by <file> and <line> is the beginning of an eval block that contains some complex code.)

Stepping through the code in a debugger, I have found that the error is trigger by the "bless" statement in this constructor, located in a different file:

sub new { my ($class) = @_; my $self = new <module-name>; bless $self, $class; return $self; }

I am puzzled because the code worked fine in a previous version. I am in the middle of a complex merge and don't see any obvious changes that could have caused this error. In particular, none of the modules directly involved uses the "overload" pragma.

Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: Invoking bless triggers "Can't resolve method ..." error
by choroba (Cardinal) on Jul 08, 2015 at 20:48 UTC
    What is "module-name"? Does that module use overload? What's in $class at the moment of the blessing?
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Thanks for replying!

      I replaced the name of the parent class with <module-name>. It is a module written by me that does not use "overload" and is currently used as-is in production code.

      The variable $class contains the name of the current package, which is also used as-is in production code and does not use "overload".

      I don't use "overload" much. It appears in my code base only a few times, and none of the uses appears to have anything to do with the line causing the error.

        I replaced the name of the parent class with <module-name>. […] The variable $class contains the name of the current package ...

        I assume that <module-name> is a valid class name. The quoted statements suggest to me that the class <module-name> and the "current package", i.e., class, are not the same. IOW, you are creating an object of class <module-name> and then severing the connection of object data to that class by re-bless-ing the object into a class which has an unknown (to me, at least) relationship to the generating class. This seems to me to be a very good recipe for major Brain Hurt.

        Is there any reason not to use the "standard" instantiation process, i.e., use the new constructor of the parent/base/super class, then add data, etc., to the object appropriate to the child/derived/sub class before returning the object reference?


        Give a man a fish:  <%-(-(-(-<

        The variable $class contains the name of the current package

        How exactly did you inspect the contents of $class? Did you use the debugger or something like Data::Dump, or did you simply print it?

        At this point we're just giving educated guesses; I suggest you boil the problem down to a short, runnable example (see http://sscce.org/) that reproduces the problem.

Re: Invoking bless triggers "Can't resolve method ..." error
by jeffa (Bishop) on Jul 08, 2015 at 20:51 UTC

    I have never seen this syntax before:

    new <module-name>;
    Is it possible that the previous version used this code as a template and substituted the module name, producing something like so?
    my $self = new Some::Valid::Module::Name;

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    

      Thanks for your reply.

      Neither the file containing the bless statement nor the file defining the parent class have been modified since the last release.

Re: Invoking bless triggers "Can't resolve method ..." error
by Anonymous Monk on Jul 08, 2015 at 21:37 UTC

    Could you tell us the version of Perl you're using, and the result of running the script via perl -Mdiagnostics=-traceonly my_script.pl?

      Yes, perl --version outputs:

      This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi

      The production environment uses the same Perl.

      When I first ran the script with -Mdiagnostics=-traceonly, I got about forty notices about harmless but slightly wrong usage. After I resolved these issues, all I am left with is:

      Uncaught exception from user code: Can't resolve method "name" overloading """" in package "overl +oad" at <file> line <line>. at <file> line <line>
Re: Invoking bless triggers "Can't resolve method ..." error
by Anonymous Monk on Jul 09, 2015 at 09:02 UTC
    Do you have a package called overload somewhere?

    What's the output of

    sub new { my ($class) = @_; my $self = new <module-name>; use Devel::Peek; # insert this Dump $class; # into your program bless $self, $class; return $self; }