http://qs321.pair.com?node_id=126092

czarfred has asked for the wisdom of the Perl Monks concerning the following question:

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.