#!/usr/bin/perl -w use Test::More tests => 10; use Data::Dumper; use DBI; use lib('lib'); use My::New::Module; my $vasbe = My::New::Module->new(); isa_ok($vasbe,'My::New::Module'); my $dir = "/home/hesco/sb/My-New-Module/"; my $file = 'vasample.csv'; my $table = 'vasample'; my $cols = [qw( random memberid address1 address2 county local state zip zip4 hod vasenate congress district )]; my $sep = ','; my $dbh = DBI->connect( "DBI:CSV:f_dir=$dir;csv_eol=\n;csv_sep_char=$sep;", {RaiseError=>1}, ); print STDERR "The connection is made.\n"; $dbh->{'csv_tables'}->{'vasample'} = { 'file' => 'vasample.csv', 'col_names' => $cols, }; print STDERR "Our tables are defined.\n"; my $sql = "SELECT memberid, address1, zip, hod, vasenate, congress, district FROM $table;"; my $sth = $dbh->prepare($sql) or die "Cannot prepare query: " . $sql . "|<-->|" . $dbh->errstr(); $sth->execute() or die "Cannot execute: " . $sth->errstr(); print STDERR "We've executed this query: $sql.\n"; print STDERR "Which returned " . $sth->rows() . " records.\n"; while (my $row = $sth->fetchrow_hashref) { print("Found result row: id = ", $row->{'memberid'}, ", zip = ", $row->{'zip'}); } print STDERR " . . . and printed a row for each record.\n"; my %address = ( 'streetnumber' => '', 'streetname' => '', 'zipcode' => '', ); print STDERR "We've now built the \%address hash.\n"; my $result = &match_address( \%address ); END { print "And now the program is terminating.\n"; $sth->finish(); $dbh->disconnect(); } 1; # with subroutines following # STDERR / STDOUT follows: t/12_vasbe_testcases.t 1..10 ok 1 - The object isa My::New::Module The connection is made. Our tables are defined. SQL ERROR: Bad table or column name 'vasample;' has chars not alphanumeric or underscore! We've executed this query: SELECT memberid, address1, zip, hod, vasenate, congress, district FROM vasample;. Which returned 1 records. Use of uninitialized value in print at t/12_vasbe_testcases.t line 52. Use of uninitialized value in print at t/12_vasbe_testcases.t line 52. Found result row: id = , zip = . . . and printed a row for each record. We've now built the %address hash. . . . successfully runs the mocked tests. And now the program is terminating.