| 1 | package TAP::Parser::SourceHandler::RawTAP; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 33 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 33 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 33 | ▶ | use TAP::Parser::IteratorFactory (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 33 | ▶ | use TAP::Parser::Iterator::Array (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 33 | ▶ | use base 'TAP::Parser::SourceHandler'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 33 | TAP::Parser::IteratorFactory->register_handler(__PACKAGE__); | |||||||||||||
| 12 | |||||||||||||||
| 13 | =head1 NAME | ||||||||||||||
| 14 | |||||||||||||||
| 15 | TAP::Parser::SourceHandler::RawTAP - Stream output from raw TAP in a scalar/array ref. | ||||||||||||||
| 16 | |||||||||||||||
| 17 | =head1 VERSION | ||||||||||||||
| 18 | |||||||||||||||
| 19 | Version 3.52 | ||||||||||||||
| 20 | |||||||||||||||
| 21 | =cut | ||||||||||||||
| 22 | |||||||||||||||
| 23 | 33 | our $VERSION = '3.52'; | |||||||||||||
| 24 | |||||||||||||||
| 25 | =head1 SYNOPSIS | ||||||||||||||
| 26 | |||||||||||||||
| 27 | use TAP::Parser::Source; | ||||||||||||||
| 28 | use TAP::Parser::SourceHandler::RawTAP; | ||||||||||||||
| 29 | |||||||||||||||
| 30 | my $source = TAP::Parser::Source->new->raw( \"1..1\nok 1\n" ); | ||||||||||||||
| 31 | $source->assemble_meta; | ||||||||||||||
| 32 | |||||||||||||||
| 33 | my $class = 'TAP::Parser::SourceHandler::RawTAP'; | ||||||||||||||
| 34 | my $vote = $class->can_handle( $source ); | ||||||||||||||
| 35 | my $iter = $class->make_iterator( $source ); | ||||||||||||||
| 36 | |||||||||||||||
| 37 | =head1 DESCRIPTION | ||||||||||||||
| 38 | |||||||||||||||
| 39 | This is a I<raw TAP output> L<TAP::Parser::SourceHandler> - it has 2 jobs: | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 1. Figure out if the L<TAP::Parser::Source> it's given is raw TAP output | ||||||||||||||
| 42 | (L</can_handle>). | ||||||||||||||
| 43 | |||||||||||||||
| 44 | 2. Creates an iterator for raw TAP output (L</make_iterator>). | ||||||||||||||
| 45 | |||||||||||||||
| 46 | Unless you're writing a plugin or subclassing L<TAP::Parser>, you probably | ||||||||||||||
| 47 | won't need to use this module directly. | ||||||||||||||
| 48 | |||||||||||||||
| 49 | =head1 METHODS | ||||||||||||||
| 50 | |||||||||||||||
| 51 | =head2 Class Methods | ||||||||||||||
| 52 | |||||||||||||||
| 53 | =head3 C<can_handle> | ||||||||||||||
| 54 | |||||||||||||||
| 55 | my $vote = $class->can_handle( $source ); | ||||||||||||||
| 56 | |||||||||||||||
| 57 | Only votes if $source is an array, or a scalar with newlines. Casts the | ||||||||||||||
| 58 | following votes: | ||||||||||||||
| 59 | |||||||||||||||
| 60 | 0.9 if it's a scalar with '..' in it | ||||||||||||||
| 61 | 0.7 if it's a scalar with 'ok' in it | ||||||||||||||
| 62 | 0.3 if it's just a scalar with newlines | ||||||||||||||
| 63 | 0.5 if it's an array | ||||||||||||||
| 64 | |||||||||||||||
| 65 | =cut | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 365 | ▶ | sub can_handle { | ||||||||||||
|
Subroutine
can_handle: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||
| 68 | 365 | my ( $class, $src ) = @_; | |||||||||||||
| 69 | 365 | my $meta = $src->meta; | |||||||||||||
| 70 | |||||||||||||||
| 71 | 365 | ▶ | return 0 if $meta->{file}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 72 | 89 | ▶ | if ( $meta->{is_scalar} ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 73 | 66 | ▶ | return 0 unless $meta->{has_newlines}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 74 | 65 | ▶ | return 0.9 if ${ $src->raw } =~ /\d\.\.\d/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 75 | 4 | ▶ | return 0.7 if ${ $src->raw } =~ /ok/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | 2 | return 0.3; | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | elsif ( $meta->{is_array} ) { | ||||||||||||||
| 79 | 4 | return 0.5; | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | 19 | return 0; | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | |||||||||||||||
| 84 | =head3 C<make_iterator> | ||||||||||||||
| 85 | |||||||||||||||
| 86 | my $iterator = $class->make_iterator( $source ); | ||||||||||||||
| 87 | |||||||||||||||
| 88 | Returns a new L<TAP::Parser::Iterator::Array> for the source. | ||||||||||||||
| 89 | C<$source-E<gt>raw> must be an array ref, or a scalar ref. | ||||||||||||||
| 90 | |||||||||||||||
| 91 | C<croak>s on error. | ||||||||||||||
| 92 | |||||||||||||||
| 93 | =cut | ||||||||||||||
| 94 | |||||||||||||||
| 95 | 66 | ▶ | sub make_iterator { | ||||||||||||
|
Subroutine
make_iterator: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||
| 96 | 66 | my ( $class, $src ) = @_; | |||||||||||||
| 97 | 66 | my $meta = $src->meta; | |||||||||||||
| 98 | |||||||||||||||
| 99 | 66 | my $tap_array; | |||||||||||||
| 100 | 66 | ▶ | if ( $meta->{is_scalar} ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 101 | 63 | $tap_array = [ split "\n" => ${ $src->raw } ]; | |||||||||||||
| 102 | } | ||||||||||||||
| 103 | elsif ( $meta->{is_array} ) { | ||||||||||||||
| 104 | 3 | $tap_array = $src->raw; | |||||||||||||
| 105 | } | ||||||||||||||
| 106 | |||||||||||||||
| 107 | 66 | ▶ | $class->_croak('No raw TAP found in $source->raw') | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 108 | unless scalar $tap_array; | ||||||||||||||
| 109 | |||||||||||||||
| 110 | 66 | return TAP::Parser::Iterator::Array->new($tap_array); | |||||||||||||
| 111 | } | ||||||||||||||
| 112 | |||||||||||||||
| 113 | 33 | 1; | |||||||||||||
| 114 | |||||||||||||||
| 115 | =head1 SUBCLASSING | ||||||||||||||
| 116 | |||||||||||||||
| 117 | Please see L<TAP::Parser/SUBCLASSING> for a subclassing overview. | ||||||||||||||
| 118 | |||||||||||||||
| 119 | =head1 SEE ALSO | ||||||||||||||
| 120 | |||||||||||||||
| 121 | L<TAP::Object>, | ||||||||||||||
| 122 | L<TAP::Parser>, | ||||||||||||||
| 123 | L<TAP::Parser::IteratorFactory>, | ||||||||||||||
| 124 | L<TAP::Parser::SourceHandler>, | ||||||||||||||
| 125 | L<TAP::Parser::SourceHandler::Executable>, | ||||||||||||||
| 126 | L<TAP::Parser::SourceHandler::Perl>, | ||||||||||||||
| 127 | L<TAP::Parser::SourceHandler::File>, | ||||||||||||||
| 128 | L<TAP::Parser::SourceHandler::Handle> | ||||||||||||||
| 129 | |||||||||||||||
| 130 | =cut | ||||||||||||||