I am trying to create a module that sets up environment variables from another module, creates a database handle and passes it back to the calling script.
I understand that an object exists as long as there is a reference to it but cant quite see why this code generates the following errors when it tries to destroy the dbh even though it is always an object in the hash? No doubt I am confused about a fundamental here.
Issuing rollback() for database handle being DESTROY'd without explici +t disconnect() at ./poe_ctrl.pl line 38. $VAR1 = bless( { '_dbh' => bless( {}, 'DBI::db' ) }, 'SDU::DB' ); Issuing rollback() for database handle being DESTROY'd without explici +t disconnect(). ------------------------------------------------------------ Script to create the connection poe_ctrl.pl use warnings; use strict; use Data::Dumper; use POE qw(Wheel::Run Filter::Reference); use SDU::CommandIterator; use SDU::DB; use SDU::Config; sub MAX_CONCURRENT_TASKS () { 5 } # Create database connection my $dbh = SDU::DB->new; print Dumper($dbh); exit; ------------------------------------------------------------ Package to create the connection package SDU::DB; require 5.008 ; use SDU::Config; use strict; use Carp; use Carp qw(cluck); use DBI; use DBI qw(:sql_types); use DBD::Oracle; use DBD::Oracle qw(:ora_types); use TNBException; sub new { my $class = shift; my $SC = SDU::Config->new; my $DB = { _dbh => &ConnectToOracle($SC) }; my $DC = &ConnectToOracle($SC); my $self = bless $DB, $class; return $self; } sub ConnectToOracle{ my ($SC) = @_; $ENV{ORACLE_HOME}=$SC->{ORA_HOME}; $ENV{TWO_TASK}=$SC->{ORA_SID}; $ENV{ORACLE_SID}=$SC->{ORA_SID}; my $combined=$SC->{ORA_USER}."@".$SC->{ORA_SID}; my $trace_level=0; my $dbh = undef; $dbh = DBI->connect('dbi:Oracle:',$combined , $SC->{ORA_PASS}) or +throw TNBCriticalException($dbh->errstr); $dbh->func( 1000000, 'dbms_output_enable' ); $dbh->{RaiseError} = 1; $dbh->{PrintError} = 0; $dbh->{AutoCommit} = 0; $dbh->trace($trace_level); return $dbh; } 1;

In reply to DBI and Modules by set_uk

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.