isshino has asked for the wisdom of the Perl Monks concerning the following question:
Hi I'm new to Perl and I'm trying to create an OO Module and I'm having trouble running it. I get the following error:
Can't locate object method "new" via package "testModule" at testFile.pl line 6
Here's my testModule file:
#!/usr/bin/perl package testModule; use strict; use warnings; sub new{ my $class = shift; my $self = {}; bless $self, $class; return $self; } sub printSomething{ return 'Something!'; } 1;
I used h2xs -XAn testModule to create a directory and then used:
Perl Makefile.PL
make
make install
to install the module. I'm using Perlv 5.8.8 on a macbook with MacOS V-10.5.7
Then I try to use the module on the following file:
#!/usr/bin/perl -w use strict; use testModule; my $ob = new testModule; print $ob->printSomething;
And I get the error I mentioned above when I try to run the test file. Any ideas why? there's certainly a new method on my testModule file. And I'm assuming it installed correctly because I'm using Komodo to edit the files, and it autocompletes the function printSomething on my testFile.
Any help would be greatly appreciated!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can't locate object method 'new' ??
by BrowserUk (Patriarch) on Aug 27, 2009 at 23:18 UTC | |
by isshino (Initiate) on Aug 28, 2009 at 02:12 UTC | |
|
Re: Can't locate object method 'new' ??
by stevieb (Canon) on Aug 27, 2009 at 23:15 UTC | |
|
Re: Can't locate object method 'new' ??
by perlkiller (Acolyte) on Aug 27, 2009 at 23:23 UTC | |
by chromatic (Archbishop) on Aug 28, 2009 at 00:59 UTC | |
|