NAME

VERSION

Version 3.39

SYNOPSIS

# abstract class - don't use directly!# see TAP::Parser::IteratorFactory for general usage# must be sub-classed for usepackageMySourceHandler;usebase'TAP::Parser::SourceHandler';sub can_handle {return$confidence_level}sub make_iterator {return$iterator}# see example below for more details

METHODS

Class Methods

can_handle

Returns a number between 0 & 1 reflecting how confidently the raw source can be handled. For example, 0 means the source cannot handle it, 0.5 means it may be able to, and 1 means it definitely can. See "detect_source" in TAP::Parser::IteratorFactory for details on how this is used.

Example

packageMySourceHandler;usestrict;useMySourceHandler;# see TAP::Parser::SourceHandleruseTAP::Parser::IteratorFactory;usebase'TAP::Parser::SourceHandler';TAP::Parser::IteratorFactory->register_handler(__PACKAGE__);sub can_handle {my($class,$src)=@_;my$meta=$src->meta;my$config=$src->config_for($class);if($config->{accept_all}){return1.0;}elsif(my$file=$meta->{file}){return0.0unless$file->{exists};return1.0if$file->{lc_ext}eq'.tap';return0.9if$file->{shebang}&&$file->{shebang}=~/^#!.+tap/;return0.5if$file->{text};return0.1if$file->{binary};}elsif($meta->{scalar}){return0.8if$$raw_source_ref=~/\d\.\.\d/;return0.6if$meta->{has_newlines};}elsif($meta->{array}){return0.8if$meta->{size}<5;return0.6if$raw_source_ref->[0]=~/foo/;return0.5;}elsif($meta->{hash}){return0.6if$raw_source_ref->{foo};return0.2;}return0;}sub make_iterator {my($class,$source)=@_;# this is where you manipulate the source and# capture the stream of TAP in an iterator# either pick a TAP::Parser::Iterator::* or write your own...my$iterator=TAP::Parser::Iterator::Array->new(['foo','bar']);return$iterator;}1;