in reply to Problem with calling method new

Quoth the Camel (3ed, p927):

You used the syntax of a method call, but the slot filled by the objec +t reference or package name contains an expression that returns a def +ined value that is neither an object reference nor a package name. So +mething like this will reproduce the error: $BADREF = 42; process $BADREF 1,2,3; $BADREF->process(1,2,3);

To make a long story short, you probably have a package named Voice, with a method named Calendar(). Instead of a class method invocation, you're calling &Voice::Calendar(), which returns something that is a true value, but not an object reference or package. Example:

$ perl -e 'package Foo::Bar; sub Foo {1}; sub Foo::Bar {1}; package ma +in; Foo::Bar->Foo' Can't call method "Foo" without a package or object reference at -e li +ne 1.

To prevent this confusion, you can quote the package name:

'Foo::Bar'->Foo

conv

Update: Of course there's a package named Voice, I should read more carefully.

For fun: You could also have made the Calendar() method in the Voice package return 'Voice::Calendar', which Perl would take as the package name, but that would probably break other stuff. (:

Replies are listed 'Best First'.
Re: Re: Problem with calling method new
by Sinister (Friar) on Sep 21, 2001 at 12:29 UTC
    Quoting the package name did the trick!

    Thanks, ever so much!
    IOU a beer now!
    I would have never found out myself!

    Sinister greetings.
    "With tying hashes you can do everything God and Larry have forbidden" -- Johan Vromans - YAPC::Europe 2001
    perldoc -q $_