1 package TAP::Parser::Source;
4 use vars qw($VERSION @ISA);
7 use TAP::Parser::IteratorFactory ();
9 @ISA = qw(TAP::Object);
11 # Causes problem on MacOS and shouldn't be necessary anyway
12 #$SIG{CHLD} = sub { wait };
16 TAP::Parser::Source - Stream output from some source
28 use TAP::Parser::Source;
29 my $source = TAP::Parser::Source->new;
30 my $stream = $source->source(['/usr/bin/ruby', 'mytest.rb'])->get_stream;
34 Takes a command and hopefully returns a stream from it.
42 my $source = TAP::Parser::Source->new;
44 Returns a new C<TAP::Parser::Source> object.
48 # new() implementation supplied by TAP::Object
51 my ( $self, $args ) = @_;
52 $self->{switches} = [];
53 _autoflush( \*STDOUT );
54 _autoflush( \*STDERR );
58 ##############################################################################
60 =head2 Instance Methods
64 my $source = $source->source;
65 $source->source(['./some_prog some_test_file']);
68 $source->source(['/usr/bin/ruby', 't/ruby_test.rb']);
70 Getter/setter for the source. The source should generally consist of an array
71 reference of strings which, when executed via L<&IPC::Open3::open3|IPC::Open3>,
72 should return a filehandle which returns successive rows of TAP. C<croaks> if
73 it doesn't get an arrayref.
79 return $self->{source} unless @_;
80 unless ( 'ARRAY' eq ref $_[0] ) {
81 $self->_croak('Argument to &source must be an array reference');
83 $self->{source} = shift;
87 ##############################################################################
91 my $stream = $source->get_stream;
93 Returns a L<TAP::Parser::Iterator> stream of the output generated by executing
94 C<source>. C<croak>s if there was no command found.
96 Must be passed an object that implements a C<make_iterator> method.
97 Typically this is a TAP::Parser instance.
102 my ( $self, $factory ) = @_;
103 my @command = $self->_get_command
104 or $self->_croak('No command found!');
106 return $factory->make_iterator(
107 { command => \@command,
108 merge => $self->merge
113 sub _get_command { return @{ shift->source || [] } }
115 ##############################################################################
119 my $merge = $source->merge;
121 Sets or returns the flag that dictates whether STDOUT and STDERR are merged.
127 return $self->{merge} unless @_;
128 $self->{merge} = shift;
132 # Turns on autoflush for the handle passed
135 my $old_fh = select $flushed;
144 Please see L<TAP::Parser/SUBCLASSING> for a subclassing overview.
148 package MyRubySource;
153 use Carp qw( croak );
154 use TAP::Parser::Source;
156 @ISA = qw( TAP::Parser::Source );
158 # expect $source->(['mytest.rb', 'cmdline', 'args']);
160 my ($self, $args) = @_;
161 my ($rb_file) = @$args;
162 croak("error: Ruby file '$rb_file' not found!") unless (-f $rb_file);
163 return $self->SUPER::source(['/usr/bin/ruby', @$args]);
170 L<TAP::Parser::Source::Perl>,