[VPM] Can't locate method via ...
Peter Scott
Peter at PSDT.com
Mon Jan 26 12:22:24 CST 2004
At 09:52 AM 1/26/2004 -0800, Carl B. Constantine wrote:
>I have some perl code that was written by someone else. It's a package
>that was tacked on the end of a regular perl script. So I ripped it out
>and pasted it into it's own package file and gave it a name:
>UVic::Tempfiles.
>
>First I get an error about unable to locate UVic/Tempfiles even though I
>have a use lib line. It turns out that I had to put it in a UVic subdir.
>But other UVic:: modules did not produce that error, so I'm curious why
>they don't need to be in the Subdir but mine does?
If a module's name begins with "Uvic::" then it will be found by a use
statement if and only if it is located in a subdirectory called UVic
under one of the directories in @INC. I'm sure if you inspect closely
you'll find this to be the case.
>Anyway, the main point is this module defines the method HoldInput, but
>I get this error when I try to create a new version of this object:
>
>Can't locate object method "HoldInput" via package "Tempfiles"
>(perhaps you forgot to load "Tempfiles"?) at
>/etc/localhost/arms/lib/UVic/Tempfiles.pm line 29.
>
>But that method IS defined.
That means you were trying to call it as :
Tempfiles->HoldInput
instead of by its real name:
UVic::Tempfiles->HoldInput
The colons in a class name are part of the name. Their only
significance is in defining a directory structure for where a .pm file
will be searched for by a use or require statement.
>Additionally, I tried to put it in the
>Exporter line at the top of the module file to no avail:
>
>use Exporter;
>@ISA = ('Exporter');
>@EXPORT=qw(&new
> &HoldInput
> &Temppath);
You don't want the ampersands there... I'm fairly sure they change the
meaning. Not a good idea to export a function with a name as generic
as 'new' either. I rarely eexport names. I think you're much better
just calling them as class methods:
UVic::Tempfiles->HoldInput
etc, which don't require exporting.
>I've tried putting HoldInput above the 'new' method, also to no avail.
>
>Anyone know what I'm doing wrong? This has worked before just as is
>(older perl mind you) and I haven't modified anything, just copy and
>paste. So what's up?
You changed the structure and syntax along with your cutting and
pasting, and/or broke an incorrect assumption about how to use objects.
>The Camel book says that "you called a method correctly, and it
>correctly indicated a package functionion as a class, but that package
>doesn't define that perticular method, nor does any of its base
>classes."
>
>Huh? it does so, right in the package!
>
>--
>Carl B. Constantine University of Victoria
>Programmer Analyst http://www.csc.uvic.ca
>UNIX System Administrator Victoria, BC, Canada
>cconstan at csc.uvic.ca ELW A248, 721-8766
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/
*** New! *** http://www.perlmedic.com/
More information about the Victoria-pm
mailing list