new: Implement verification of $dbh
The two previously committed tests now pass: ok 2 - new: dies when dbh is undefined. ok 3 - new: dies when dbh is blessed into another module.
This commit is contained in:
parent
470b889c3e
commit
aef01b3031
2 changed files with 13 additions and 7 deletions
|
@ -27,7 +27,7 @@ our @EXPORT = qw(
|
||||||
|
|
||||||
our $VERSION = '0.02';
|
our $VERSION = '0.02';
|
||||||
|
|
||||||
use Scalar::Util qw(looks_like_number);
|
use Scalar::Util qw(looks_like_number blessed);
|
||||||
use Mail::RFC822::Address;
|
use Mail::RFC822::Address;
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
@ -42,8 +42,9 @@ Arguments:
|
||||||
|
|
||||||
=item $dbh
|
=item $dbh
|
||||||
|
|
||||||
Scalar references for the database handle, already opened and pointing to
|
Scalar references for the database handle from the L<DBI>, already opened
|
||||||
the right database.
|
and pointing to the right database. This class will take over and control
|
||||||
|
the DBI object after C<new()> completes.
|
||||||
|
|
||||||
=item $ledgerCmd
|
=item $ledgerCmd
|
||||||
|
|
||||||
|
@ -58,8 +59,13 @@ sub new ($$) {
|
||||||
my $package = shift;
|
my $package = shift;
|
||||||
my($dbh, $ledgerCmd) = @_;
|
my($dbh, $ledgerCmd) = @_;
|
||||||
|
|
||||||
return bless({ dbh => $dbh, ledgerCmd => $ledgerCmd },
|
my $self = bless({ dbh => $dbh, ledgerCmd => $ledgerCmd },
|
||||||
$package);
|
$package);
|
||||||
|
|
||||||
|
die "new: first argument must be a database handle"
|
||||||
|
unless (defined $dbh and blessed($dbh) =~ /DBI/);
|
||||||
|
|
||||||
|
return $self;
|
||||||
}
|
}
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Test::More tests => 61;
|
use Test::More tests => 63;
|
||||||
use Test::Exception;
|
use Test::Exception;
|
||||||
|
|
||||||
use Scalar::Util qw(looks_like_number reftype blessed);
|
use Scalar::Util qw(looks_like_number reftype);
|
||||||
|
|
||||||
=pod
|
=pod
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue