App-MtAws

 view release on metacpan or  search on metacpan

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

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
        $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

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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.247 second using v1.01-cache-2.11-cpan-e5176c747c2 )