#!/usr/local/bin/perl -w use Daemon; my $app = Daemon->new(); while (1) { $app->do_something(); print scalar(localtime)." Sleeping 5 seconds...\n"; sleep 5; } -------8<-------------------------------- package Daemon; use Data::Dumper; use Handle; { sub _createConnection { my $self = shift; my %args = @_; my $retval; $self->{dbo} = Handle->new( handle => 'handle', user => 'jwilliams', pwd => 'type895', sid => 'ossp1',) if (! $self->{dbo} ); } } sub new { my ($caller, %arg) = @_; my $caller_is_obj = ref($caller); my $class = $caller_is_obj || $caller; my $self = bless {}, $class; return $self; } sub do_something { my $self = shift; my %args = @_; $self->_createConnection(); undef $self->{dbo}; return 'status message'; } 1 -------8<-------------------------------- package Handle; use Data::Dumper; $VERSION = 1.00; use strict; use DBI; use Carp; use Hook::LexWrap; { sub _get_db_handle { my ($self, %args) = @_; croak "Must supply username" unless ($args{user}); croak "Must supply password" unless ($args{pwd}); croak "Must supply SID" unless ($args{sid}); my $dsn = "DBI:Oracle:".$args{sid}; #set the dataset name my %attr = ( RaiseError => 1, PrintError => 0, AutoCommit => 1 || $self->{_AutoCommit} ); #set error raising and printing # lets go get the handle my $handle = DBI->connect($dsn,$args{user},$args{pwd}, \%attr); $handle->{InactiveDestroy} = 1; croak "Unable to connect to ".$args{sid} unless ($handle); return $handle; } } sub new { my ($caller, %arg) = @_; my $caller_is_obj = ref($caller); my $class = $caller_is_obj || $caller; my $self = bless {}, $class; $arg{engine} = 'oracle' if (!defined $arg{engine} ); $self->{_db_handle}{$arg{engine}}{$arg{handle}} = $self->_get_db_handle(%arg); wrap 'DESTROY', pre => \&predestroy, post=> \&postdestroy; return $self; } sub predestroy { print STDERR "predestroy: ".Dumper(@_); } sub postdestroy { print STDERR "postdestroy: ".Dumper(@_); } sub DESTROY { my $self = shift; foreach my $handle ( keys %{$self->{_db_handle}{'oracle'}} ) { # non bug condition, the object is correctly referenced #$self->{_db_handle}{'oracle'}{$handle}->disconnect; # bug condition, the object is incorrectly referenced $self->{_db_handle}{$handle}->disconnect; } } 1 -------8<-------------------------------- SQL> l 1 select username, to_char(logon_time, 'dd-mon-yyyy hh24:mi:ss') as logon from v$session 2* where username = '' SQL>