1 package TAP::Parser::Source;
6 use TAP::Parser::Iterator ();
8 # Causes problem on MacOS and shouldn't be necessary anyway
9 #$SIG{CHLD} = sub { wait };
13 TAP::Parser::Source - Stream output from some source
25 Takes a command and hopefully returns a stream from it.
29 use TAP::Parser::Source;
30 my $source = TAP::Parser::Source->new;
31 my $stream = $source->source(['/usr/bin/ruby', 'mytest.rb'])->get_stream;
39 my $source = TAP::Parser::Source->new;
41 Returns a new C<TAP::Parser::Source> object.
47 _autoflush( \*STDOUT );
48 _autoflush( \*STDERR );
49 bless { switches => [] }, $class;
52 ##############################################################################
54 =head2 Instance Methods
58 my $source = $source->source;
59 $source->source(['./some_prog some_test_file']);
62 $source->source(['/usr/bin/ruby', 't/ruby_test.rb']);
64 Getter/setter for the source. The source should generally consist of an array
65 reference of strings which, when executed via L<&IPC::Open3::open3|IPC::Open3>, should
66 return a filehandle which returns successive rows of TAP.
72 return $self->{source} unless @_;
73 unless ( 'ARRAY' eq ref $_[0] ) {
74 $self->_croak('Argument to &source must be an array reference');
76 $self->{source} = shift;
80 ##############################################################################
84 my $stream = $source->get_stream;
86 Returns a stream of the output generated by executing C<source>.
92 my @command = $self->_get_command
93 or $self->_croak('No command found!');
95 return TAP::Parser::Iterator->new(
96 { command => \@command,
102 sub _get_command { return @{ shift->source || [] } }
104 ##############################################################################
108 unless ( my $stream = $source->get_stream ) {
112 If a stream cannot be created, this method will return the error.
118 return $self->{error} unless @_;
119 $self->{error} = shift;
123 ##############################################################################
127 my $exit = $source->exit;
129 Returns the exit status of the process I<if and only if> an error occurs in
136 return $self->{exit} unless @_;
137 $self->{exit} = shift;
141 ##############################################################################
145 my $merge = $source->merge;
147 Sets or returns the flag that dictates whether STDOUT and STDERR are merged.
153 return $self->{merge} unless @_;
154 $self->{merge} = shift;
158 # Turns on autoflush for the handle passed
161 my $old_fh = select $flushed;