Please ignore the previous message (Clicked create instead of Add More
Files).
Basically, DEMOLISH is causing an error to be thrown.
(in cleanup) Can't call method "has_value" on an undefined value at
/usr/local/lib/perl/5.12.4/Class/MOP/Class.pm line 862 during global
destruction.
Attached is minimal code to recreate the error. I also cannot seem to
combine them into a single file or remove the _setup accessor withou the
error disappearing.
I only seem to get the issue when using MooseX::Singleton and not
straight Moose but I'm not entirely certain it is a MooseX bug.
Tried with Moose 2.0204 and 2.0401.
package SingletonObj;
use v5.12.4;
use MooseX::Singleton;
has '_dbh' => (
is => 'rw',
isa => 'DBI::db',
);
has '_setup' => ( is => 'rw', isa => 'Int', default => 0 );
sub setup {
my $self = shift;
if ( not $self->_setup ) {
# Perform configuration of singleton
}
return;
}
sub connected {
my $self = shift;
# Used to check _dbh->ping here too but determined the overhead
# could be too high as this function may be called several times
# during a single page build.
if ( $self->_dbh ) {
say "Return DB State";
}
return 0;
}
sub DEMOLISH {
my ($self) = @_;
if ( $self->connected ) {
say "Disconnect from DB";
}
return;
}
1;
#!/usr/bin/env perl
use v5.12.4;
use SingletonObj;
my $setupDBH = SingletonObj->setup( { user => 'auto' } );