]> git.vpit.fr Git - perl/modules/Test-Leaner.git/blob - t/lib/Test/Leaner/TestHelper.pm
29db429aa17eaecb528fe31d9d44f48ea088ccf7
[perl/modules/Test-Leaner.git] / t / lib / Test / Leaner / TestHelper.pm
1 package Test::Leaner::TestHelper;
2
3 use strict;
4 use warnings;
5
6 my $memory_stream;
7 my $buf_ref;
8
9 sub capture_to_buffer {
10  return unless "$]" >= 5.008;
11
12  die "Can't call capture_to_buffer twice" if $memory_stream;
13
14  $buf_ref = \$_[0];
15  open $memory_stream, '>', $buf_ref
16                            or die 'could not create the in-memory file';
17
18  Test::Leaner::tap_stream($memory_stream);
19
20  return 1;
21 }
22
23 # The ";&" prototype does not work well with perl 5.6
24 sub reset_buffer (&) {
25  my $code = shift;
26
27  die "The memory stream has not been initialized" unless $memory_stream;
28
29  $$buf_ref = '';
30  seek $memory_stream, 0, 0;
31
32  goto $code if $code;
33 }
34
35 our @EXPORT = qw<
36  capture_to_buffer
37  reset_buffer
38 >;
39
40 use Exporter ();
41
42 sub import { goto &Exporter::import }
43
44 1;