dariusj has asked for the wisdom of the Perl Monks concerning the following question:
tools.pm#! /usr/bin/perl -wT #use strict; use CGI; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use DBI; use vars qw($DBH $CGI); use lib "./"; use tools; #require Exporter; #our @ISA = qw(Exporter); #our @EXPORT = qw(); $DBH = DBI->connect('DBI:mysql:youtrivia','xxx','xxx', {'RaiseError' = +> 1, 'AutoCommit' => 0}) or die "Couldn't connect: " . DBI->errstr; my $CGI = CGI->new(); my $action = $CGI->param("submit"); print $CGI->header; print $CGI->start_html(-title=>"Add User"); my $tools = tools->new(); $tools->display_add_user($CGI,$DBH); print $CGI->end_html; exit(0);
When I try not using the "CGI::" bit I get an error like so in my browser:package tools; use strict; use CGI; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use DBI; use Digest::MD5; use vars qw($DBH $CGI); sub new { my ($this) = shift; my $class = ref($this) || $this; my $self = {}; bless ($self, $class); return $self; } sub display_add_user { my $cgi = shift; my $dbh = shift; print "<h1>Add user</h1>"; print $cgi->CGI::start_multipart_form(-method=>'post', -action=>'./adduser.pl', -name=>'add_user'); print "<table>"; print "<tr><td>User</td>"; print "<td>".$cgi->CGI::textfield(-name=>'username',-size=>'100')."< +/td></tr>"; print "<tr><td>Password</td>"; print "<td>".$cgi->CGI::password_field(-name=>'password', -size=>'50')."</td></tr>"; print "</table>"; print $cgi->CGI::submit(-name=>'submit', -value=>'AddUser'); print $cgi->CGI::end_form; } 1;
The line number refers to the line with start_multipart_form, I cut out some other methods. Shouldn't this work also WITHOUT the CGI:: part? But when I do include CGI:: (i.e. in the code sample above) the text and password fields are displayed ignoring all arguments, with -name written in the text field by default and something else (starred) in the password field, and the two fields are the same size! Can anyone see what I'm doing wrong? Thanks!Can't locate object method "start_multipart_form" via package "tools" +at /tools.pm line 155.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl namespace issue driving me nuts!
by shmem (Chancellor) on Jul 16, 2007 at 12:19 UTC | |
by dariusj (Sexton) on Jul 16, 2007 at 12:24 UTC | |
|
Re: Perl namespace issue driving me nuts!
by moritz (Cardinal) on Jul 16, 2007 at 12:20 UTC | |
by dariusj (Sexton) on Jul 16, 2007 at 12:25 UTC |