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');
}