I'm having a lot of trouble with the following code: (bluebox.pm)
package bluebox;
use base 'CGI::Application';
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use strict;
sub setup {
my $self = shift;
$self->mode_param('mode');
$self->start_mode('list');
$self->run_modes(
'list' => \&list,
'view' => \&view,
'edit' => \&edit,
'new' => \&new,
'del' => \&del
);
$self->param('dbh' => DBI->connect('dbi:mysql:adb, 'user', 'pass', {
+RaiseError => 1, AutoCommit => 0 }));
}
sub teardown {
my $self = shift;
$self->param('dbh')->disconnect();
}
sub list {
my $self = shift;
my $q = $self->query();
my $output;
my $dbh = $self->param('dbh');
$output .= $q->header();
$output .= $q->start_html();
$output .= "This is the list page.\n";
$output .= $q->end_html;
return $output;
}
sub view {
my $self = shift;
my $q = $self->query();
my $output;
my $dbh = $self->param('dbh');
return $output;
}
sub edit {
my $self = shift;
my $q = $self->query();
my $output;
my $dbh = $self->param('dbh');
return $output;
}
sub new {
my $self = shift;
my $q = $self->query();
my $output;
my $dbh = $self->param('dbh');
return $output;
}
sub del {
my $self = shift;
my $q = $self->query();
my $output;
my $dbh = $self->param('dbh');
return $output;
}
1;
And as for the instance script: (bluebox.cgi)
#!/usr/bin/perl -w
use bluebox;
use strict;
my $book = bluebox->new();
$book->run();
AS you can see, I have not implemented the different modes' subs yet (or I just have test prints where it would be), but that shouldn't have anything to do with the problem.
When I run the instance script (on a apache server at localhost, with the module in @INC), I get the following errors:
Can't use string ("bluebox") as a HASH ref while "strict refs" in use
+at /usr/lib/perl5/site_perl/5.6.0/CGI/Application.pm line 361.
Does anyone have any ideas? This this something im doing, or is it maybe a bug (seems unlikely).
Also, what the monks here think about CGI::Application? FYI, this is going to eventully turn out to be an online phone book app (this isnt even the framework for the full implementation, just mostly trying out CGI::Application). Am I using CGI::Application in the right way? Any suggestion on the code so far would be greatly appreciated.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.