LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-16-2003, 09:18 PM   #1
cobien
LQ Newbie
 
Registered: Nov 2003
Posts: 1

Rep: Reputation: 0
Angry Perl undefined subroutine /can't locate object method


Hi ,
I modified an exisitng perl module called Noc1.pm by adding sub isadmin in this file.
I tested this new added function with test_noc.pl and it works fine.
However, when i used it in another file called test_noc.html in the exactly same way i used
in test_noc.pl . I got the following error msg.

Can't locate object method "isadmin" via package "Noc1" at /var/apache/cgi-bin/test_noc.html line 20.

Undefined subroutine &Noc1::isadmin called at /var/apache/cgi-bin/test_noc.html line 20.

Please help.

=====Noc1.pm=====

package Noc1;
use strict;
use Noc:B;

sub new
{
my $self = shift;
my $object = ref( $self );
my $class = $object || $self;

$self = {};
bless $self, $class;
return $self;
} # new


sub new_CGI
{
my $self = shift;

return $self->{ q } = new CGI;
} # new_CGI




sub isadmin
{ my $self = shift;


my $uid = shift;

open (LOG_FILE, ">>/var/apache/cgi-bin/tam.log")||die "Error Writing Log File: $!\n";
print LOG_FILE scalar(localtime), ": admin is calling\n";
print LOG_FILE scalar(localtime), ": my uid and admin is \n";
print LOG_FILE scalar(localtime), ": ". $uid."\n" ;


close LOG_FILE;
$self->{admin} = $self->{db}->{dbh}->selectrow_array(qq{
SELECT admin FROM users
WHERE uid = $uid }) unless defined $self->{ admin };
return ($self->{admin} and $self->{admin} eq 'Y') ? 1 : 0;
}
# isadmin


---more here----


1;


====test_noc.pl=======
#!/usr/bin/perl -w
use strict;
use Noc1;

my $noc = new Noc1;

#my $q = $noc->new_CGI;
my $dbh = $noc->connect_db;
my $login = $dbh->quote(lc("mylogin"));

my $pw = $dbh->quote("mypassowrd");


my ( $uid, $public, $email ) = $dbh->selectrow_array( qq{
SELECT uid, public, email FROM users
WHERE LOWER( login )=$login
AND password=$pw
} );
my $admin = $noc->isadmin($uid);
print "admin " ;

print $admin;
print"\n";



======test_noc.html=====

#!/usr/bin/perl -w
use strict;
use Noc1;

my $noc = new Noc1;

#my $q = $noc->new_CGI;
my $dbh = $noc->connect_db;
my $login = $dbh->quote(lc("mylogin"));

my $pw = $dbh->quote("my password");
my ($left_frame, $center_frame, $right_frame_top, $right_frame_bottom, $public_docs, $escalation);


my ( $uid, $public, $email ) = $dbh->selectrow_array( qq{
SELECT uid, public, email FROM users
WHERE LOWER( login )=$login
AND password=$pw
} );
my $admin = $noc->isadmin($uid); <======error occurs here


open (LOG_FILE, ">>/var/apache/cgi-bin/tam.log")||die "Error Writing Log File: $!\n";

print LOG_FILE scalar(localtime), ": www: my uid and admin is \n";
print LOG_FILE scalar(localtime), $uid ;


close LOG_FILE;
if($admin){
$right_frame_top = $noc->load_html('/var/apache/htdocs/.frontpage_templates/admin.html');
}
 
Old 11-17-2003, 10:47 AM   #2
JoAnywhere
Member
 
Registered: Oct 2003
Location: denver
Distribution: Debian
Posts: 97

Rep: Reputation: 15
Try adding a line like this at the top of your test_noc script

require '/the/directory/my/module/is/in/myperlstuff.pl';

That having been said, I am a real perl newbie.

Regards
Jo
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl subroutine call shifty_eyes Programming 2 10-01-2005 08:43 PM
How can I tell one object to do a method in javascript? eantoranz Programming 1 10-29-2004 01:20 PM
Can't locate object method "splitpath" via package "File::Spec" RobJohnston Linux - General 2 06-28-2003 09:59 AM
Need Perl/CGI help! Undefined Subroutine CragStar Programming 4 03-05-2002 07:28 AM
Perl Subroutine problem sykkn Programming 0 02-20-2002 09:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration