For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > June 2007 > Re: Error:Can't locate object method "prepare" via package "abc"









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Error:Can't locate object method "prepare" via package "abc"
Chas Owens

2007-06-01, 7:58 am

On 5/31/07, Jonathan Lang <dataweaver@gmail.com> wrote:
snip
> Again, you have a signature problem. 'sub new($)' says that 'new'
> will take a single scalar as a parameter; as such, @_ will only ever
> have one value in it: $usr and $pwd will always be set to null.

snip

Well, there is a prototype problem, but it isn't that $ will force new
to only accept one value, but rather that prototypes and OO Perl don't
mix. Perl simply ignores prototypes on methods. Also prototypes are
broken*, don't use them.

#!/usr/bin/perl

use strict;
use warnings;

package foo;

sub new ($) {
my $class = shift;
return bless { @_ }, $class;
}

package main;

my $foo = foo->new(this => 1, that => 2);

print "this $foo->{this} and that $foo->{that}\n";

* http://library.n0i.net/programming/.../fm_prototypes/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com