cosmicperl has asked for the wisdom of the Perl Monks concerning the following question:
Hi All,
I recently updated my Database routines to be object orientated, but I seem to have broken carp..
Example:-
If for instance there is a problem connecting, with code like:-
Shouldn't this be showing my calling script and not the module?
What am I missing :s
Lyle
Update: Crackers2 pointed out my example didn't properly illustrate the problem I'm having, it was an example showing correct behavious of another scripts carp. The new example above shows my problem
I recently updated my Database routines to be object orientated, but I seem to have broken carp..
Example:-
package db_base; use strict; use DBI; use CGI::Carp qw( fatalsToBrowser ); sub new { my ( $class, $DSN, $user, $pass, $param ) = @_; $param = {} unless ref( $param ); my $self = { param => { %$param, dsn => $DSN, user => $user, pass => $pass, }, }; bless( $self, $class ); return $self; }#new sub connect_db { my $self = shift; unless ($self->{param}->{connect}) { $self->{dbh} = DBI->connect( $self->{param}->{dsn}, $self->{pa +ram}->{user}, $self->{param}->{pass} ) || croak("Cannot connect to database: $DBI::errstr\n$::bac +khtml"); $self->{param}->{connect} = 1; }#unless }#sub sub insert { my ( $self, $table, $columns, $data ) = @_; $self->{param}->{success} = 0; my $sql = "INSERT INTO `$table` (`" . join( "`,`", @$columns ) . ' +`) values(' . join( ",", map {'?'} @$columns ) . ')'; my $sth = $self->{dbh}->prepare($sql); $sth->execute(@$data) && {$self->{param}->{success} = 1} || croak( +"Cannot insert to $table: SQL = $sql\n $DBI::errstr\n$::backhtml"); }#sub
If for instance there is a problem connecting, with code like:-
I get an error like:-use db_base; my $dbobj = new db_base( 'dsn', 'user', 'pass'); $dbobj->connect; $dbobj->insert( 'test_table', [ 'column' ], [ 'value' ]);
Cannot insert to test_test_table: SQL = INSERT INTO `test_test_table` +(`column`) values(?) Table 'affiliate.test_test_table' doesn't exist at c:/inetpub/wwwroot/cgi-bin/affiliate/db_base.pm line 52
Shouldn't this be showing my calling script and not the module?
What am I missing :s
Lyle
Update: Crackers2 pointed out my example didn't properly illustrate the problem I'm having, it was an example showing correct behavious of another scripts carp. The new example above shows my problem
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Carp not working after change to objects
by Crackers2 (Parson) on May 16, 2008 at 01:52 UTC | |
by cosmicperl (Chaplain) on May 16, 2008 at 02:40 UTC | |
Re: Carp not working after change to objects
by snoopy (Curate) on May 16, 2008 at 04:06 UTC | |
by cosmicperl (Chaplain) on May 16, 2008 at 14:03 UTC | |
by snoopy (Curate) on May 17, 2008 at 02:12 UTC |
Back to
Seekers of Perl Wisdom