TAP::Parser::Source - TAP 來源及相關的元資料
版本 3.44
use TAP::Parser::Source;
my $source = TAP::Parser::Source->new;
$source->raw( \'reference to raw TAP source' )
->config( \%config )
->merge( $boolean )
->switches( \@switches )
->test_args( \@args )
->assemble_meta;
do { ... } if $source->meta->{is_file};
# see assemble_meta for a full list of data available
TAP 來源會產生 TAP 串流,供剖析器使用,例如執行檔、文字檔、封存檔、IO 處理器、資料庫等等。TAP::Parser::Source
s 封裝這些原始來源,並提供一些有用的元資料。它們會由 TAP::Parser::SourceHandlers 使用,後者會執行任何必要的動作,以從原始來源產生並擷取 TAP 串流,並將其封裝在 TAP::Parser::Iterator 中,供剖析器使用。
除非您要撰寫新的 TAP::Parser::SourceHandler、外掛程式或 TAP::Parser 子類別,否則您可能不需要直接使用這個模組。
new
my $source = TAP::Parser::Source->new;
傳回新的 TAP::Parser::Source
物件。
raw
my $raw = $source->raw;
$source->raw( $some_value );
串接原始 TAP 來源的 getter/setter。這是一個參考,因為它可能包含大量資料(例如:原始 TAP)。
meta
my $meta = $source->meta;
$source->meta({ %some_value });
串接來源的 meta 資料的 getter/setter。這預設為空的雜湊參考。有關更多資訊,請參閱 "assemble_meta"。
has_meta
如果來源有 meta 資料,則為 True。
config
my $config = $source->config;
$source->config({ %some_value });
串接來源組態的 getter/setter,如果使用者已提供任何組態。如何使用它取決於您。這預設為空的雜湊參考。有關更多資訊,請參閱 "config_for"。
merge
my $merge = $source->merge;
$source->config( $bool );
串接旗標的 getter/setter,指示是否應合併 STDOUT 和 STDERR(在適當的情況下)。預設為未定義。
switches
my $switches = $source->switches;
$source->config([ @switches ]);
串接應傳遞給來源的命令列開關清單的 getter/setter(在適當的情況下)。預設為未定義。
test_args
my $test_args = $source->test_args;
$source->config([ @test_args ]);
串接應傳遞給來源的命令列引數清單的 getter/setter(在適當的情況下)。預設為未定義。
assemble_meta
my $meta = $source->assemble_meta;
收集有關 "raw" 來源的 meta 資料,將其儲存在 "meta" 中,並以雜湊參考的形式傳回。這樣做是為了讓 TAP::Parser::SourceHandler 不必重複執行常見的檢查。目前這包括
is_scalar => $bool,
is_hash => $bool,
is_array => $bool,
# for scalars:
length => $n
has_newlines => $bool
# only done if the scalar looks like a filename
is_file => $bool,
is_dir => $bool,
is_symlink => $bool,
file => {
# only done if the scalar looks like a filename
basename => $string, # including ext
dir => $string,
ext => $string,
lc_ext => $string,
# system checks
exists => $bool,
stat => [ ... ], # perldoc -f stat
empty => $bool,
size => $n,
text => $bool,
binary => $bool,
read => $bool,
write => $bool,
execute => $bool,
setuid => $bool,
setgid => $bool,
sticky => $bool,
is_file => $bool,
is_dir => $bool,
is_symlink => $bool,
# only done if the file's a symlink
lstat => [ ... ], # perldoc -f lstat
# only done if the file's a readable text file
shebang => $first_line,
}
# for arrays:
size => $n,
shebang
取得腳本檔案的 shebang 行。
my $shebang = TAP::Parser::Source->shebang( $some_script );
可以作為類別方法呼叫
config_for
my $config = $source->config_for( $class );
傳回給定 $class 的 "config"。類別名稱可以完全限定或縮寫,例如
# these are equivalent
$source->config_for( 'Perl' );
$source->config_for( 'TAP::Parser::SourceHandler::Perl' );
如果給定完全限定的 $class,則會先檢查其縮寫版本。
Steve Purkis。
TAP::Object、TAP::Parser、TAP::Parser::IteratorFactory、TAP::Parser::SourceHandler