Handle.pm revision 1.1
1package TAP::Parser::SourceHandler::Handle; 2 3use strict; 4use vars qw($VERSION @ISA); 5 6use TAP::Parser::SourceHandler (); 7use TAP::Parser::IteratorFactory (); 8use TAP::Parser::Iterator::Stream (); 9 10@ISA = qw(TAP::Parser::SourceHandler); 11 12TAP::Parser::IteratorFactory->register_handler(__PACKAGE__); 13 14=head1 NAME 15 16TAP::Parser::SourceHandler::Handle - Stream TAP from an IO::Handle or a GLOB. 17 18=head1 VERSION 19 20Version 3.23 21 22=cut 23 24$VERSION = '3.23'; 25 26=head1 SYNOPSIS 27 28 use TAP::Parser::Source; 29 use TAP::Parser::SourceHandler::Executable; 30 31 my $source = TAP::Parser::Source->new->raw( \*TAP_FILE ); 32 $source->assemble_meta; 33 34 my $class = 'TAP::Parser::SourceHandler::Handle'; 35 my $vote = $class->can_handle( $source ); 36 my $iter = $class->make_iterator( $source ); 37 38=head1 DESCRIPTION 39 40This is a I<raw TAP stored in an IO Handle> L<TAP::Parser::SourceHandler> class. It 41has 2 jobs: 42 431. Figure out if the L<TAP::Parser::Source> it's given is an L<IO::Handle> or 44GLOB containing raw TAP output (L</can_handle>). 45 462. Creates an iterator for IO::Handle's & globs (L</make_iterator>). 47 48Unless you're writing a plugin or subclassing L<TAP::Parser>, you probably 49won't need to use this module directly. 50 51=head1 METHODS 52 53=head2 Class Methods 54 55=head3 C<can_handle> 56 57 my $vote = $class->can_handle( $source ); 58 59Casts the following votes: 60 61 0.9 if $source is an IO::Handle 62 0.8 if $source is a glob 63 64=cut 65 66sub can_handle { 67 my ( $class, $src ) = @_; 68 my $meta = $src->meta; 69 70 return 0.9 71 if $meta->{is_object} 72 && UNIVERSAL::isa( $src->raw, 'IO::Handle' ); 73 74 return 0.8 if $meta->{is_glob}; 75 76 return 0; 77} 78 79=head3 C<make_iterator> 80 81 my $iterator = $class->make_iterator( $source ); 82 83Returns a new L<TAP::Parser::Iterator::Stream> for the source. 84 85=cut 86 87sub make_iterator { 88 my ( $class, $source ) = @_; 89 90 $class->_croak('$source->raw must be a glob ref or an IO::Handle') 91 unless $source->meta->{is_glob} 92 || UNIVERSAL::isa( $source->raw, 'IO::Handle' ); 93 94 return $class->iterator_class->new( $source->raw ); 95} 96 97=head3 C<iterator_class> 98 99The class of iterator to use, override if you're sub-classing. Defaults 100to L<TAP::Parser::Iterator::Stream>. 101 102=cut 103 104use constant iterator_class => 'TAP::Parser::Iterator::Stream'; 105 1061; 107 108=head1 SUBCLASSING 109 110Please see L<TAP::Parser/SUBCLASSING> for a subclassing overview. 111 112=head1 SEE ALSO 113 114L<TAP::Object>, 115L<TAP::Parser>, 116L<TAP::Parser::Iterator>, 117L<TAP::Parser::Iterator::Stream>, 118L<TAP::Parser::IteratorFactory>, 119L<TAP::Parser::SourceHandler>, 120L<TAP::Parser::SourceHandler::Executable>, 121L<TAP::Parser::SourceHandler::Perl>, 122L<TAP::Parser::SourceHandler::File>, 123L<TAP::Parser::SourceHandler::RawTAP> 124 125=cut 126