<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package TAP::Parser::SourceHandler::File;

use strict;
use warnings;

use TAP::Parser::IteratorFactory  ();
use TAP::Parser::Iterator::Stream ();

use base 'TAP::Parser::SourceHandler';

TAP::Parser::IteratorFactory-&gt;register_handler(__PACKAGE__);

=head1 NAME

TAP::Parser::SourceHandler::File - Stream TAP from a text file.

=head1 VERSION

Version 3.42

=cut

our $VERSION = '3.42';

=head1 SYNOPSIS

  use TAP::Parser::Source;
  use TAP::Parser::SourceHandler::File;

  my $source = TAP::Parser::Source-&gt;new-&gt;raw( \'file.tap' );
  $source-&gt;assemble_meta;

  my $class = 'TAP::Parser::SourceHandler::File';
  my $vote  = $class-&gt;can_handle( $source );
  my $iter  = $class-&gt;make_iterator( $source );

=head1 DESCRIPTION

This is a I&lt;raw TAP stored in a file&gt; L&lt;TAP::Parser::SourceHandler&gt; - it has 2 jobs:

1. Figure out if the I&lt;raw&gt; source it's given is a file containing raw TAP
output.  See L&lt;TAP::Parser::IteratorFactory&gt; for more details.

2. Takes raw TAP from the text file given, and converts into an iterator.

Unless you're writing a plugin or subclassing L&lt;TAP::Parser&gt;, you probably
won't need to use this module directly.

=head1 METHODS

=head2 Class Methods

=head3 C&lt;can_handle&gt;

  my $vote = $class-&gt;can_handle( $source );

Only votes if $source looks like a regular file.  Casts the following votes:

  0.9 if it's a .tap file
  0.9 if it has an extension matching any given in user config.

=cut

sub can_handle {
    my ( $class, $src ) = @_;
    my $meta   = $src-&gt;meta;
    my $config = $src-&gt;config_for($class);

    return 0 unless $meta-&gt;{is_file};
    my $file = $meta-&gt;{file};
    return 0.9 if $file-&gt;{lc_ext} eq '.tap';

    if ( my $exts = $config-&gt;{extensions} ) {
        my @exts = ref $exts eq 'ARRAY' ? @$exts : $exts;
        return 0.9 if grep { lc($_) eq $file-&gt;{lc_ext} } @exts;
    }

    return 0;
}

=head3 C&lt;make_iterator&gt;

  my $iterator = $class-&gt;make_iterator( $source );

Returns a new L&lt;TAP::Parser::Iterator::Stream&gt; for the source.  C&lt;croak&gt;s
on error.

=cut

sub make_iterator {
    my ( $class, $source ) = @_;

    $class-&gt;_croak('$source-&gt;raw must be a scalar ref')
      unless $source-&gt;meta-&gt;{is_scalar};

    my $file = ${ $source-&gt;raw };
    my $fh;
    open( $fh, '&lt;', $file )
      or $class-&gt;_croak("error opening TAP source file '$file': $!");
    return $class-&gt;iterator_class-&gt;new($fh);
}

=head3 C&lt;iterator_class&gt;

The class of iterator to use, override if you're sub-classing.  Defaults
to L&lt;TAP::Parser::Iterator::Stream&gt;.

=cut

use constant iterator_class =&gt; 'TAP::Parser::Iterator::Stream';

1;

__END__

=head1 CONFIGURATION

  {
   extensions =&gt; [ @case_insensitive_exts_to_match ]
  }

=head1 SUBCLASSING

Please see L&lt;TAP::Parser/SUBCLASSING&gt; for a subclassing overview.

=head1 SEE ALSO

L&lt;TAP::Object&gt;,
L&lt;TAP::Parser&gt;,
L&lt;TAP::Parser::SourceHandler&gt;,
L&lt;TAP::Parser::SourceHandler::Executable&gt;,
L&lt;TAP::Parser::SourceHandler::Perl&gt;,
L&lt;TAP::Parser::SourceHandler::Handle&gt;,
L&lt;TAP::Parser::SourceHandler::RawTAP&gt;

=cut
</pre></body></html>