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

Hallowed monks,

UPDATE:As per CountZero's advice, I moved use Notes::DBI into cgiapp_init, wrapped it in an eval and used require and returned $@ What I got was this:Error executing class callback in init stage: DBIx::Class::Schema::load_classes(): DBIx::Class::Relationship::BelongsTo::belongs_to(): Can't locate Notes/DBI/User.pm in @INC (@INC contains: /usr/lib/perl5/5.8.7/i686-linux /usr/lib/perl5/5.8.7 /usr/lib/perl5/site_perl/5.8.7/i686-linux /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl .) at (eval 53) line 3.. Long story short, Notes::DBI::User.pm was named Notes::DBI::Users.pm, thus throwing DBIx::Class into a tizzy and causing all sorts of trouble. /me thinks it would be nice to have some method (aside from wrapping it in eval, as that would be used when expecting a possible error in this case)to make this return an error in such a way that CGI scripts don't completely die when this type of error is thrown...

I'm at my wits end. I'm using DBIx::Class and it seems to be hanging up at __PACKAGE__->load_classes(). I think. When I take use Notes::DBI (my main schema class) out of my code, my code runs fine. As far as I can tell, I've narrowed it down to __PACKAGE__->load_classes(), the only error i get is a "premature end of script headers" error (using CGI::Application, along with an assortment of config modules, etc.)

This near exact same code works fine for another web app i'm working on, so i'm stumped.

Here's the code:

Notes.pm:

package Notes;
use strict; use base 'CGI::Application'; use Notes::DBI; use CGI::Session; use CGI::Application::Plugin::TT; # for template toolkit support use Config::Simple; #use CGI::Application::Plugin::Config::Simple; # for Config::Simple su +pport; #use CGI::Session; use CGI::Carp qw[fatalsToBrowser]; #DEBUG ONLY
...
sub main { my $self = shift; my $config = Config::Simple->new("conf/notes.conf"); my $session = CGI::Session->load("driver:File", $self->query, { Di +rectory => $config->param('session_directory') } ) or CGI::Session->new("driver:File", $self->query, { Directory + => $config->param('session_directory') } ) or die CGI::Session->errstr; ### get a db connection my $schema = Note::DBI->connect($config->param('db_data_source'), $config->param('db_username'), $config->param('db_password'), { RaiseError => 1, AutoCommit => 1 + }); my @all_notes = $schema->resultset('Notes')->all; ### create a query for @usernotes, does not actually ### execute query my $user_notes = $schema->resultset('User')->search( { username => $session->param('username') } ); # Get all the user's notes my @all_user_notes = $user_notes->search_related('notes')->all; return $self->tt_process('main.tt', { c => $self->query, s => $session, #a_notes => \@all_notes, #u_notes => \@all_user_notes, title => 'Notes Home' }); }

Notes::DBI (main schema class):

package Notes::DBI; use strict; use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_classes(); ## hopefully won't slow things down
1;

Notes::DBI::User (user table class)

package Notes::DBI::Users; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/ PK::Auto Core /);
__PACKAGE__->table('users'); __PACKAGE__->add_columns( qw/ userid username password create_date last_here email notes_are_private / ); __PACKAGE__->set_primary_key('userid'); __PACKAGE__->has_many( notes => 'Notes::DBI::Notes'); 1;

Notes::DBI::Notes (notes table class):

package Notes::DBI::Notes; use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/ PK::Auto Core /); __PACKAGE__->table('notes'); __PACKAGE__->add_columns( qw/ noteid date number content user private class / ); __PACKAGE__->set_primary_key('noteid'); __PACKAGE__->belongs_to( user => 'Notes::DBI::User');
1;

I'm spent. Tell me if this is completely idiotic and I'm missing something right in front of my face, or if it's an actual issue.

meh.

Replies are listed 'Best First'.
Re: DBIx::Class issues : ->load_classes()?
by castaway (Parson) on Oct 27, 2006 at 06:57 UTC
    I assume the "Premature end of script headers" is in the web server error log? What happens if you just run it on the command-line?

    Also, you can extract the "use Notes::DBI; Notes::DBI->connect .. " into a test script and just run that, what happens then?

    C.

Re: DBIx::Class issues : ->load_classes()?
by graq (Curate) on Oct 27, 2006 at 07:28 UTC
    It looks like the script is generating an error and returning that to the web server before the server gets a proper header. If that error is not in the webserver log files, then you need to capture it another way, either by running it from the command line (as per castaway's suggestion), or forcing a header to the browser.

    -=( Graq )=-

Re: DBIx::Class issues : ->load_classes()?
by CountZero (Bishop) on Oct 27, 2006 at 10:53 UTC
    You definitely need to get hold of the real error message rather than the web-server error.

    Perhaps wrapping the __PACKAGE__->load_classes(); in an eval and then checking for an error which you can direct to your browser using use CGI::Carp qw(fatalsToBrowser);?

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law