Test::Trap::Builder::TempFile - Output layer backend using File::Temp


Test-Trap documentation Contained in the Test-Trap distribution.

Index


Code Index:

NAME

Top

Test::Trap::Builder::TempFile - Output layer backend using File::Temp

VERSION

Top

Version 0.2.1

DESCRIPTION

Top

This module provides an implementation tempfile, based on File::Temp, for the trap's output layers. Note that you may specify different implementations for each output layer on the trap.

See also Test::Trap (:stdout and :stderr) and Test::Trap::Builder (output_layer).

CAVEATS

Top

Using File::Temp, we need privileges to create tempfiles.

We need disk space for the output of every trap (it should clean up after the trap is sprung).

Disk access may be slow -- certainly compared to the in-memory files of PerlIO.

Threads? No idea. It might even work correctly.

BUGS

Top

Please report any bugs or feature requests directly to the author.

AUTHOR

Top

Eirik Berg Hanssen, <ebhanssen@allverden.no>

COPYRIGHT & LICENSE

Top


Test-Trap documentation Contained in the Test-Trap distribution.

package Test::Trap::Builder::TempFile;

use version; $VERSION = qv('0.2.1');

use strict;
use warnings;
use IO::Handle;
use File::Temp qw( tempfile );
use Test::Trap::Builder;

sub import {
  Test::Trap::Builder->output_layer_backend( tempfile => $_ ) for sub {
    my $self = shift;
    my ($name, $fileno, $globref) = @_;
    my $pid = $$;
    my ($fh, $file) = tempfile( UNLINK => 1 ); # XXX: Test?
    $self->Teardown($_) for sub {
      # if the file is opened by some other process, that one should deal with it:
      return unless $pid == $$;
      local $/;
      $self->{$name} .= <$fh>;
      close $fh;
    };
    binmode $fh; # superfluos?
    local *$globref;
    {
      no warnings 'io';
      open *$globref, '>>', $file;
    }
    binmode *$globref; # must write as we read.
    *$globref->autoflush(1);
    $self->Next;
  };
}

1; # End of Test::Trap::Builder::TempFile

__END__