App-MtAws

 view release on metacpan or  search on metacpan

lib/App/MtAws/IntermediateFile.pm  view on Meta::CPAN

	$self->{tmp} = eval {
		# PID is needed cause child processes re-use random number generators, improves performance only, no risk of race cond.
		File::Temp->new(TEMPLATE => "__mtglacier_temp${$}_XXXXXX", UNLINK => 1, SUFFIX => '.tmp', DIR => $binary_dirname)
	} or do {
		die exception 'cannot_create_tempfile' =>
		'Cannot create temporary file in directory %string dir%, errors: %error%',
		dir => $dir, error => hex_dump_string($@);
	};
	my $binary_tempfile = $self->{tmp}->filename;
	$self->{tempfile} = characterfilename($binary_tempfile);
	 # it's important to close file, it's filename can be passed to different process, and it can be locked
	close $self->{tmp} or confess;
}

sub tempfilename
{
	shift->{tempfile} or confess;
}

sub make_permanent
{

t/integration/intermediate_file_ipc.t  view on Meta::CPAN

	sub {
		my ($in, $out) = @_;
		my $filename = <$in>;
		chomp $filename;
		my $data_sample = "abcdefz\n";

		ok -f $filename, "file is file";
		ok -r $filename, "file is readable";

		ok open(my $f, ">", $filename), "file opened";
		ok flock($f, LOCK_EX), "file locked";
		ok ((print $f $data_sample), "data written");
		ok (close($f), "file closed");

		ok (open(my $infile, "<", $filename), "file opened for reading");
		my $got_data = do { local $/; <$infile> };
		ok defined($got_data), "we got data";
		ok close($infile), "file closed";

		is $got_data, $data_sample, "file acts well";
		print $out "ok\n";



( run in 0.467 second using v1.01-cache-2.11-cpan-49f99fa48dc )