Database-Abstraction

 view release on metacpan or  search on metacpan

lib/Database/Abstraction.pm  view on Meta::CPAN

			last;
		}
		if($gz_file) {
			require Gzip::Faster;

			close($fin);
			$fin = File::Temp->new(SUFFIX => '.csv', UNLINK => 1);
			print $fin Gzip::Faster::gunzip_file($gz_file);
			$fin->flush();
			$slurp_file = $fin->filename();
			$self->{'_temp_fh'} = $fin;	# Keep object alive; auto-unlinks at DESTROY
		} else {
			my $psv = File::Spec->catfile($dir, "$dbname.psv");
			if(-r $psv) {
				open($fin, '<', $psv);
				# Pipe separated file
				$slurp_file = $psv;
				$params->{'sep_char'} = '|';
			} else {
				# CSV or BerkeleyDB-extension file
				for my $ext (qw(csv db)) {

t/remote.t  view on Meta::CPAN

# ---------------------------------------------------------------------------
# Section 3: DESTROY cleans up temp directory
# ---------------------------------------------------------------------------

my $tmpdir_path;
{
	my $tmp_dao = Database::remote->new(host => 'myhost', directory => '/data');
	$tmp_dao->selectall_arrayref();	# trigger _open
	my $obj = $tmp_dao->{'_remote_tmpdir'};
	$tmpdir_path = ref($obj) ? $obj->dirname() : undef;
	ok(defined($tmpdir_path) && -d $tmpdir_path, 'remote tmpdir exists while object alive');
}	# DESTROY fires here

ok(!-d $tmpdir_path, 'remote tmpdir removed after object destroyed')
	if defined($tmpdir_path);

# ---------------------------------------------------------------------------
# Section 4: Input validation — unsafe host name
# ---------------------------------------------------------------------------

throws_ok(

t/transaction.t  view on Meta::CPAN

	my $tmpdir = File::Temp->newdir(CLEANUP => 1);
	my $csv_plain = "entry!number\n\"one\"!1\n\"two\"!2\n\"three\"!3\n";
	my $gz_path   = File::Spec->catfile("$tmpdir", 'test1.csv.gz');
	gzip \$csv_plain => $gz_path or die "gzip failed: $GzipError";

	# T5-1: gzip CSV opens and returns the correct row count
	my $db_gz = Database::test1->new("$tmpdir");
	cmp_ok($db_gz->count(), '==', 3, 'T5-1: gzip CSV opens and count() == 3');

	# T5-2: during lifetime, _temp_fh holds a File::Temp object (decompressed copy)
	ok(defined $db_gz->{'_temp_fh'}, 'T5-2: _temp_fh is set while gzip object is alive');

	# T5-3: the temp file actually exists on disk during object lifetime
	my $tmpfile_path = $db_gz->{'_temp_fh'}->filename();
	ok(-e $tmpfile_path, 'T5-3: decompressed temp file exists on disk during object lifetime');

	# T5-4: multiple queries use the same temp file (no re-extraction between calls)
	my $path_after_q2 = do { $db_gz->selectall_arrayref(); $db_gz->{'_temp_fh'}->filename() };
	is($path_after_q2, $tmpfile_path,
	    'T5-4: same temp file path after second query (no re-extraction)');



( run in 1.189 second using v1.01-cache-2.11-cpan-14f38c9f855 )