| 1 | package TAP::Parser::SourceHandler::File; | ||||||||||
| 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::Stream (); | ||||||||
|
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::File - Stream TAP from a text file. | ||||||||||
| 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::File; | ||||||||||
| 29 | |||||||||||
| 30 | my $source = TAP::Parser::Source->new->raw( \'file.tap' ); | ||||||||||
| 31 | $source->assemble_meta; | ||||||||||
| 32 | |||||||||||
| 33 | my $class = 'TAP::Parser::SourceHandler::File'; | ||||||||||
| 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 stored in a file> L<TAP::Parser::SourceHandler> - it has 2 jobs: | ||||||||||
| 40 | |||||||||||
| 41 | 1. Figure out if the I<raw> source it's given is a file containing raw TAP | ||||||||||
| 42 | output. See L<TAP::Parser::IteratorFactory> for more details. | ||||||||||
| 43 | |||||||||||
| 44 | 2. Takes raw TAP from the text file given, and converts into an 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 looks like a regular file. Casts the following votes: | ||||||||||
| 58 | |||||||||||
| 59 | 0.9 if it's a .tap file | ||||||||||
| 60 | 0.9 if it has an extension matching any given in user config. | ||||||||||
| 61 | |||||||||||
| 62 | =cut | ||||||||||
| 63 | |||||||||||
| 64 | 365 | ▶ | sub can_handle { | ||||||||
|
Subroutine
can_handle: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||
| 65 | 365 | my ( $class, $src ) = @_; | |||||||||
| 66 | 365 | my $meta = $src->meta; | |||||||||
| 67 | 365 | my $config = $src->config_for($class); | |||||||||
| 68 | |||||||||||
| 69 | 365 | ▶ | return 0 unless $meta->{is_file}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 280 | my $file = $meta->{file}; | |||||||||
| 71 | 280 | ▶ | return 0.9 if $file->{lc_ext} eq '.tap'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | |||||||||||
| 73 | 277 | ▶ | if ( my $exts = $config->{extensions} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 4 | ▶ | my @exts = ref $exts eq 'ARRAY' ? @$exts : $exts; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 4 | ▶ | return 0.9 if grep { lc($_) eq $file->{lc_ext} } @exts; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 273 | return 0; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | =head3 C<make_iterator> | ||||||||||
| 82 | |||||||||||
| 83 | my $iterator = $class->make_iterator( $source ); | ||||||||||
| 84 | |||||||||||
| 85 | Returns a new L<TAP::Parser::Iterator::Stream> for the source. C<croak>s | ||||||||||
| 86 | on error. | ||||||||||
| 87 | |||||||||||
| 88 | =cut | ||||||||||
| 89 | |||||||||||
| 90 | 5 | ▶ | sub make_iterator { | ||||||||
|
Subroutine
make_iterator: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 91 | 5 | my ( $class, $source ) = @_; | |||||||||
| 92 | |||||||||||
| 93 | $class->_croak('$source->raw must be a scalar ref') | ||||||||||
| 94 | 5 | ▶ | unless $source->meta->{is_scalar}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | |||||||||||
| 96 | 5 | my $file = ${ $source->raw }; | |||||||||
| 97 | 5 | my $fh; | |||||||||
| 98 | 5 | ▶ | open( $fh, '<', $file ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | or $class->_croak("error opening TAP source file '$file': $!"); | ||||||||||
| 100 | 5 | return $class->iterator_class->new($fh); | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | =head3 C<iterator_class> | ||||||||||
| 104 | |||||||||||
| 105 | The class of iterator to use, override if you're sub-classing. Defaults | ||||||||||
| 106 | to L<TAP::Parser::Iterator::Stream>. | ||||||||||
| 107 | |||||||||||
| 108 | =cut | ||||||||||
| 109 | |||||||||||
| 110 | 33 | ▶ | use constant iterator_class => 'TAP::Parser::Iterator::Stream'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 111 | |||||||||||
| 112 | 33 | 1; | |||||||||
| 113 | |||||||||||
| 114 | __END__ | ||||||||||