Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Can't locate object method "new" via package ... perhaps you forgot to load...Oh yes I did!

by Phemto (Acolyte)
on Jan 28, 2011 at 09:58 UTC ( [id://884763]=note: print w/replies, xml ) Need Help??


in reply to Can't locate object method "new" via package ... perhaps you forgot to load...Oh yes I did!

Thanks for the input everyone. The @EXPORT was a desparate attempt to fix the problem. I should have taken it back out. Here are the complete program and module in a more minimalist form.

Here is syringe.pl

#!/usr/local/ActivePerl-5.10/bin/perl -w use strict; use warnings; use Syringe; print $INC{"Syringe.pm"}; my $syringe = Syringe->new(); print "Wohooooo!";

and here is syringe.pm, which is in the same directory.

#Package Syringe package Syringe; use strict; use warnings; @ISA = qw(Exporter); @EXPORT = qw(); @EXPORT_OK = qw(); use constant PI => 4 * atan2 1, 1; sub new { my $class = shift; my $self = {}; bless $self, $class; $self->{picture_width} = $args{picture_width}; return $self; } 1;

When I run it, I get the following results. The "use lib" line is not strictly necessary, but it forces the full module path to be printed, which assures me that there isn't some other Syringe.pm that I'm loading. The result is essentially the same as before. I'd be tempted to blame some misconfiguration in the Komodo environment, but I have other module/program pairs that I can run without problems.

Can't locate object method "new" via package "Syringe" (perhaps you fo +rgot to load "Syringe"?) at /Users/phowell/Documents/Work/Programming +/Syringe/Syringe.pl line 8. /Users/phowell/Documents/Work/Programming/Syringe/Syringe.pm
  • Comment on Re: Can't locate object method "new" via package ... perhaps you forgot to load...Oh yes I did!
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Can't locate object method "new" via package ... perhaps you forgot to load...Oh yes I did!
by Corion (Patriarch) on Jan 28, 2011 at 10:09 UTC

    Your file Syringe.pm still contains errors that strict.pm cannot let pass. So you are still loading the wrong Syringe.pm file (or loading the right one but modifying/posting the wrong one).

    First test that Syringe.pm compiles well:

    perl -Ilib -MSyringe -e1

    If this command raises any errors, then they are in Syringe.pm.

    Then, go on to put this into a (very small) Perl script:

    #!perl -w use strict; use Syringe; print "OK\n";

    Get this script to run.

    After that, continue to add stuff until it breaks again (but by then, it shouldn't).

    When debugging some "magic module loader" stuff (which I've since come to abhor, for the ugly things hidden by magic module loading), I've often resorted to putting BEGIN blocks into the modules that output "I am here" messages:

    package My::Module; BEGIN { print "Loading " . __PACKAGE__ . " from " . __FILE__ . "\n"}; ... the methods in My::Module ... print "Loaded " . __PACKAGE__ . " from " . __FILE__ . "\n"; 1; __END__

    This spews a lot of messages, but on the upside, you get a trace of what module gets loaded from where (and when). If there is a "Loading..." message, but no corresponding "Loaded..." message, then you know that there was an error and something along the way gobbled up and hid that error instead of stopping execution.

Re^2: Can't locate object method "new" via package ... perhaps you forgot to load...Oh yes I did!
by GrandFather (Saint) on Jan 28, 2011 at 10:21 UTC

    Your description is not consistent with the code you provide! Syringe.pm does not compile due to the exporter related lines and due to the $self->{picture_width} = $args{picture_width}; line.

    The output from the print $INC{"Syringe.pm"}; line is consistent with a file called Syringe.pm being found in the same directory as the .pl file so the implication is that the file being loaded is not the one you think it is. Have you two files with different case perhaps, or maybe the file you are editing is in a different directory than the .pl file, but there is an old version of the .pm that is being found?

    True laziness is hard work

      GrandFather gets the cigar - along with everyone else who told me that it couldn't be the same file. When I followed his advice and stopped trusting the IDE, and went back to the terminal, it was obvious. That explains why I wasn't seeing the compilation errors, even when I "asked for them."

      I hunted down the files that were getting loaded, moved them to my working directory, and made sure the IDE was pointing to them. Now I'm getting lots of reassuring syntax errors.

      My lesson: It's not true laziness to depend on the IDE. When in doubt, drop to the command line and make sure you really know whats going on.

      Thanks Folks!

        I use Komodo all the time for Perl development under Windows. If I hover the cursor over a document tab it shows me the full path to the document. In a case like this that is a worth while sanity check!

        True laziness is hard work
Re^2: Can't locate object method "new" via package ... perhaps you forgot to load...Oh yes I did!
by DrHyde (Prior) on Jan 28, 2011 at 10:55 UTC
    is it syringe.pm or Syringe.pm? There's a difference.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://884763]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2024-04-18 14:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found