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({ parser => $parser });
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({ parser => $parser });
44 Returns a new C<TAP::Parser::Source> object.
48 # new() implementation supplied by TAP::Object
51 my ( $self, $args ) = @_;
52 $self->{switches} = [];
53 $self->{parser} = $args->{parser}; # TODO: accessor
54 _autoflush( \*STDOUT );
55 _autoflush( \*STDERR );
59 ##############################################################################
61 =head2 Instance Methods
65 my $source = $source->source;
66 $source->source(['./some_prog some_test_file']);
69 $source->source(['/usr/bin/ruby', 't/ruby_test.rb']);
71 Getter/setter for the source. The source should generally consist of an array
72 reference of strings which, when executed via L<&IPC::Open3::open3|IPC::Open3>,
73 should return a filehandle which returns successive rows of TAP. C<croaks> if
74 it doesn't get an arrayref.
80 return $self->{source} unless @_;
81 unless ( 'ARRAY' eq ref $_[0] ) {
82 $self->_croak('Argument to &source must be an array reference');
84 $self->{source} = shift;
88 ##############################################################################
92 my $stream = $source->get_stream;
94 Returns a L<TAP::Parser::Iterator> stream of the output generated by executing
95 C<source>. C<croak>s if there was no command found.
101 my @command = $self->_get_command
102 or $self->_croak('No command found!');
104 return $self->{parser}->make_iterator(
105 { command => \@command,
106 merge => $self->merge
111 sub _get_command { return @{ shift->source || [] } }
113 ##############################################################################
117 my $merge = $source->merge;
119 Sets or returns the flag that dictates whether STDOUT and STDERR are merged.
125 return $self->{merge} unless @_;
126 $self->{merge} = shift;
130 # Turns on autoflush for the handle passed
133 my $old_fh = select $flushed;
142 Please see L<TAP::Parser/SUBCLASSING> for a subclassing overview.
146 package MyRubySource;
151 use Carp qw( croak );
152 use TAP::Parser::Source;
154 @ISA = qw( TAP::Parser::Source );
156 # expect $source->(['mytest.rb', 'cmdline', 'args']);
158 my ($self, $args) = @_;
159 my ($rb_file) = @$args;
160 croak("error: Ruby file '$rb_file' not found!") unless (-f $rb_file);
161 return $self->SUPER::source(['/usr/bin/ruby', @$args]);
168 L<TAP::Parser::Source::Perl>,