Perl: Update "prove" and add its dependencies so it actually works (again)
[msysgit.git] / lib / perl5 / 5.8.8 / TAP / Parser / SourceHandler / RawTAP.pm
blob0d7a4851ee8f9114e06d58160955fd9b898e1cf2
1 package TAP::Parser::SourceHandler::RawTAP;
3 use strict;
4 use vars qw($VERSION @ISA);
6 use TAP::Parser::SourceHandler ();
7 use TAP::Parser::IteratorFactory ();
8 use TAP::Parser::Iterator::Array ();
10 @ISA = qw(TAP::Parser::SourceHandler);
12 TAP::Parser::IteratorFactory->register_handler(__PACKAGE__);
14 =head1 NAME
16 TAP::Parser::SourceHandler::RawTAP - Stream output from raw TAP in a scalar/array ref.
18 =head1 VERSION
20 Version 3.23
22 =cut
24 $VERSION = '3.23';
26 =head1 SYNOPSIS
28 use TAP::Parser::Source;
29 use TAP::Parser::SourceHandler::RawTAP;
31 my $source = TAP::Parser::Source->new->raw( \"1..1\nok 1\n" );
32 $source->assemble_meta;
34 my $class = 'TAP::Parser::SourceHandler::RawTAP';
35 my $vote = $class->can_handle( $source );
36 my $iter = $class->make_iterator( $source );
38 =head1 DESCRIPTION
40 This is a I<raw TAP output> L<TAP::Parser::SourceHandler> - it has 2 jobs:
42 1. Figure out if the L<TAP::Parser::Source> it's given is raw TAP output
43 (L</can_handle>).
45 2. Creates an iterator for raw TAP output (L</make_iterator>).
47 Unless you're writing a plugin or subclassing L<TAP::Parser>, you probably
48 won't need to use this module directly.
50 =head1 METHODS
52 =head2 Class Methods
54 =head3 C<can_handle>
56 my $vote = $class->can_handle( $source );
58 Only votes if $source is an array, or a scalar with newlines. Casts the
59 following votes:
61 0.9 if it's a scalar with '..' in it
62 0.7 if it's a scalar with 'ok' in it
63 0.3 if it's just a scalar with newlines
64 0.5 if it's an array
66 =cut
68 sub can_handle {
69 my ( $class, $src ) = @_;
70 my $meta = $src->meta;
72 return 0 if $meta->{file};
73 if ( $meta->{is_scalar} ) {
74 return 0 unless $meta->{has_newlines};
75 return 0.9 if ${ $src->raw } =~ /\d\.\.\d/;
76 return 0.7 if ${ $src->raw } =~ /ok/;
77 return 0.3;
79 elsif ( $meta->{is_array} ) {
80 return 0.5;
82 return 0;
85 =head3 C<make_iterator>
87 my $iterator = $class->make_iterator( $source );
89 Returns a new L<TAP::Parser::Iterator::Array> for the source.
90 C<$source-E<gt>raw> must be an array ref, or a scalar ref.
92 C<croak>s on error.
94 =cut
96 sub make_iterator {
97 my ( $class, $src ) = @_;
98 my $meta = $src->meta;
100 my $tap_array;
101 if ( $meta->{is_scalar} ) {
102 $tap_array = [ split "\n" => ${ $src->raw } ];
104 elsif ( $meta->{is_array} ) {
105 $tap_array = $src->raw;
108 $class->_croak('No raw TAP found in $source->raw')
109 unless scalar $tap_array;
111 return TAP::Parser::Iterator::Array->new($tap_array);
116 =head1 SUBCLASSING
118 Please see L<TAP::Parser/SUBCLASSING> for a subclassing overview.
120 =head1 SEE ALSO
122 L<TAP::Object>,
123 L<TAP::Parser>,
124 L<TAP::Parser::IteratorFactory>,
125 L<TAP::Parser::SourceHandler>,
126 L<TAP::Parser::SourceHandler::Executable>,
127 L<TAP::Parser::SourceHandler::Perl>,
128 L<TAP::Parser::SourceHandler::File>,
129 L<TAP::Parser::SourceHandler::Handle>
131 =cut