Hi All,
  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:-
use db_base; my $dbobj = new db_base( 'dsn', 'user', 'pass'); $dbobj->connect; $dbobj->insert( 'test_table', [ 'column' ], [ 'value' ]);
I get an error like:-
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

In reply to Carp not working after change to objects by cosmicperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.