TAP::Parser::SourceHandler::Perl - 從 Perl 可執行檔串流 TAP
版本 3.44
use TAP::Parser::Source;
use TAP::Parser::SourceHandler::Perl;
my $source = TAP::Parser::Source->new->raw( \'script.pl' );
$source->assemble_meta;
my $class = 'TAP::Parser::SourceHandler::Perl';
my $vote = $class->can_handle( $source );
my $iter = $class->make_iterator( $source );
這是 Perl TAP::Parser::SourceHandler - 它有 2 個工作
1. 找出給定的 TAP::Parser::Source 實際上是否為 Perl 程式碼 ("can_handle").
2. 為 Perl 來源建立一個迭代器 ("make_iterator").
除非您正在撰寫外掛程式或建立 TAP::Parser 的子類別,否則您可能不需要直接使用這個模組。
can_handle
my $vote = $class->can_handle( $source );
只有在 $source 看起來像檔案時才投票。投下以下票數
0.9 if it has a shebang ala "#!...perl"
0.3 if it has any shebang
0.8 if it's a .t file
0.9 if it's a .pl file
0.75 if it's in a 't' directory
0.25 by default (backwards compat)
make_iterator
my $iterator = $class->make_iterator( $source );
為來源建立並傳回新的 TAP::Parser::Iterator::Process。假設 $source->raw
包含對 perl 程式碼的參照。如果找不到檔案,則會 croak
。
執行命令的建立方式如下
$perl @switches $perl_script @test_args
要使用的 perl 指令由 "get_perl" 決定。保證產生的指令會保留
PERL5LIB
PERL5OPT
Taint Mode, if set in the script's shebang
注意:產生的指令不會尊重 Perl 程式碼中定義的任何 shebang 列。這只有在您編譯自訂版本的 Perl,或您想針對一個測試使用特定版本的 Perl,而針對另一個測試使用不同版本時才會造成問題,例如
#!/path/to/a/custom_perl --some --args
#!/usr/local/perl-5.6/bin/perl -w
目前您需要撰寫外掛程式才能解決這個問題。
get_taint
從 Perl shebang 列解碼任何 taint 開關。
# $taint will be 't'
my $taint = TAP::Parser::SourceHandler::Perl->get_taint( '#!/usr/bin/perl -t' );
# $untaint will be undefined
my $untaint = TAP::Parser::SourceHandler::Perl->get_taint( '#!/usr/bin/perl' );
get_perl
取得目前執行測試套件的 Perl 版本。
請參閱 "TAP::Parser 中的 SUBCLASSING" 以取得子類別概觀。
package MyPerlSourceHandler;
use strict;
use TAP::Parser::SourceHandler::Perl;
use base 'TAP::Parser::SourceHandler::Perl';
# use the version of perl from the shebang line in the test file
sub get_perl {
my $self = shift;
if (my $shebang = $self->shebang( $self->{file} )) {
$shebang =~ /^#!(.*\bperl.*?)(?:(?:\s)|(?:$))/;
return $1 if $1;
}
return $self->SUPER::get_perl(@_);
}
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