Perl 5 version 26.3 documentation

TAP::Parser::SourceHandler::Perl

NAME

TAP::Parser::SourceHandler::Perl - Stream TAP from a Perl executable

VERSION

Version 3.38

SYNOPSIS

  1. use TAP::Parser::Source;
  2. use TAP::Parser::SourceHandler::Perl;
  3. my $source = TAP::Parser::Source->new->raw( \'script.pl' );
  4. $source->assemble_meta;
  5. my $class = 'TAP::Parser::SourceHandler::Perl';
  6. my $vote = $class->can_handle( $source );
  7. my $iter = $class->make_iterator( $source );

DESCRIPTION

This is a Perl TAP::Parser::SourceHandler - it has 2 jobs:

1. Figure out if the TAP::Parser::Source it's given is actually a Perl script (can_handle).

2. Creates an iterator for Perl sources (make_iterator).

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

METHODS

Class Methods

can_handle

  1. my $vote = $class->can_handle( $source );

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

  1. 0.9 if it has a shebang ala "#!...perl"
  2. 0.75 if it has any shebang
  3. 0.8 if it's a .t file
  4. 0.9 if it's a .pl file
  5. 0.75 if it's in a 't' directory
  6. 0.25 by default (backwards compat)

make_iterator

  1. my $iterator = $class->make_iterator( $source );

Constructs & returns a new TAP::Parser::Iterator::Process for the source. Assumes $source->raw contains a reference to the perl script. croak s if the file could not be found.

The command to run is built as follows:

  1. $perl @switches $perl_script @test_args

The perl command to use is determined by get_perl. The command generated is guaranteed to preserve:

  1. PERL5LIB
  2. PERL5OPT
  3. Taint Mode, if set in the script's shebang

Note: the command generated will not respect any shebang line defined in your Perl script. This is only a problem if you have compiled a custom version of Perl or if you want to use a specific version of Perl for one test and a different version for another, for example:

  1. #!/path/to/a/custom_perl --some --args
  2. #!/usr/local/perl-5.6/bin/perl -w

Currently you need to write a plugin to get around this.

get_taint

Decode any taint switches from a Perl shebang line.

  1. # $taint will be 't'
  2. my $taint = TAP::Parser::SourceHandler::Perl->get_taint( '#!/usr/bin/perl -t' );
  3. # $untaint will be undefined
  4. my $untaint = TAP::Parser::SourceHandler::Perl->get_taint( '#!/usr/bin/perl' );

get_perl

Gets the version of Perl currently running the test suite.

SUBCLASSING

Please see SUBCLASSING in TAP::Parser for a subclassing overview.

Example

  1. package MyPerlSourceHandler;
  2. use strict;
  3. use TAP::Parser::SourceHandler::Perl;
  4. use base 'TAP::Parser::SourceHandler::Perl';
  5. # use the version of perl from the shebang line in the test file
  6. sub get_perl {
  7. my $self = shift;
  8. if (my $shebang = $self->shebang( $self->{file} )) {
  9. $shebang =~ /^#!(.*\bperl.*?)(?:(?:\s)|(?:$))/;
  10. return $1 if $1;
  11. }
  12. return $self->SUPER::get_perl(@_);
  13. }

SEE ALSO

TAP::Object, TAP::Parser, TAP::Parser::IteratorFactory, TAP::Parser::SourceHandler, TAP::Parser::SourceHandler::Executable, TAP::Parser::SourceHandler::File, TAP::Parser::SourceHandler::Handle, TAP::Parser::SourceHandler::RawTAP