my
$Test
= __PACKAGE__->new;
sub
create {
my
$class
=
shift
;
my
$self
=
$class
->SUPER::create(
@_
);
$self
->{Stack}->top->
format
(Test::Builder::Formatter->new);
my
%outputs
= (
all
=>
''
,
out
=>
''
,
err
=>
''
,
todo
=>
''
,
);
$self
->{_outputs} = \
%outputs
;
my
(
$out
,
$err
,
$todo
) =
map
{ gensym() } 1..3;
tie
*$out
,
"Test::Builder::NoOutput::Tee"
, \
$outputs
{all}, \
$outputs
{out};
tie
*$err
,
"Test::Builder::NoOutput::Tee"
, \
$outputs
{all}, \
$outputs
{err};
tie
*$todo
,
"Test::Builder::NoOutput::Tee"
, \
$outputs
{all}, \
$outputs
{todo};
$self
->output(
$out
);
$self
->failure_output(
$err
);
$self
->todo_output(
$todo
);
return
$self
;
}
sub
read
{
my
$self
=
shift
;
my
$stream
=
@_
?
shift
:
'all'
;
my
$out
=
$self
->{_outputs}{
$stream
};
$self
->{_outputs}{
$stream
} =
''
;
if
(
$stream
eq
'all'
) {
my
@keys
=
keys
%{
$self
->{_outputs}};
$self
->{_outputs}{
$_
} =
''
for
@keys
;
}
return
$out
;
}
sub
TIEHANDLE {
my
(
$class
,
@refs
) =
@_
;
my
@fhs
;
for
my
$ref
(
@refs
) {
my
$fh
= Test::Builder->_new_fh(
$ref
);
push
@fhs
,
$fh
;
}
my
$self
= [
@fhs
];
return
bless
$self
,
$class
;
}
sub
PRINT {
my
$self
=
shift
;
print
$_
@_
for
@$self
;
}
sub
PRINTF {
my
$self
=
shift
;
my
$format
=
shift
;
printf
$_
@_
for
@$self
;
}
1;