Movatterモバイル変換


[0]ホーム

URL:


TAP::Parser::SourceHandler
(source,CPAN)
version 3.50
You are viewing the version of this documentation from Perl 5.41.13. This is a development version of Perl.

CONTENTS

#NAME

TAP::Parser::SourceHandler - Base class for different TAP source handlers

#VERSION

Version 3.50

#SYNOPSIS

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

#DESCRIPTION

This is an abstract base class forTAP::Parser::Source handlers / handlers.

ATAP::Parser::SourceHandler does whatever is necessary to produce & capture a stream of TAP from theraw source, and package it up in aTAP::Parser::Iterator for the parser to consume.

SourceHandlers must implement thesource detection & handling interface used byTAP::Parser::IteratorFactory. At 2 methods, the interface is pretty simple:"can_handle" and"make_source".

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

#METHODS

#Class Methods

#can_handle

Abstract method.

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

$source is aTAP::Parser::Source.

Returns a number between0 &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, and1 means it definitely can. See"detect_source" in TAP::Parser::IteratorFactory for details on how this is used.

#make_iterator

Abstract method.

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

$source is aTAP::Parser::Source.

Returns a newTAP::Parser::Iterator object for use by theTAP::Parser.croaks on error.

#SUBCLASSING

Please see"SUBCLASSING" in TAP::Parser for a subclassing overview, and any of the subclasses that ship with this module as an example. What follows is a quick overview.

Start by familiarizing yourself withTAP::Parser::Source andTAP::Parser::IteratorFactory.TAP::Parser::SourceHandler::RawTAP is the easiest sub-class to use as an example.

It's important to point out that if you want your subclass to be automatically used byTAP::Parser you'll have to and make sure it gets loaded somehow. If you're usingprove you can write anApp::Prove plugin. If you're usingTAP::Parser orTAP::Harness directly (e.g. through a custom script,ExtUtils::MakeMaker, orModule::Build) you can use theconfig option which will cause"load_sources" in TAP::Parser::IteratorFactory to load your subclass).

Don't forget to register your class with"register_handler" in TAP::Parser::IteratorFactory.

#Example

package MySourceHandler;use strict;use MySourceHandler; # see TAP::Parser::SourceHandleruse TAP::Parser::IteratorFactory;use base '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}) {        return 1.0;    } elsif (my $file = $meta->{file}) {        return 0.0 unless $file->{exists};        return 1.0 if $file->{lc_ext} eq '.tap';        return 0.9 if $file->{shebang} && $file->{shebang} =~ /^#!.+tap/;        return 0.5 if $file->{text};        return 0.1 if $file->{binary};    } elsif ($meta->{scalar}) {        return 0.8 if $$raw_source_ref =~ /\d\.\.\d/;        return 0.6 if $meta->{has_newlines};    } elsif ($meta->{array}) {        return 0.8 if $meta->{size} < 5;        return 0.6 if $raw_source_ref->[0] =~ /foo/;        return 0.5;    } elsif ($meta->{hash}) {        return 0.6 if $raw_source_ref->{foo};        return 0.2;    }    return 0;}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;

#AUTHORS

TAPx Developers.

Source detection stuff added by Steve Purkis

#SEE ALSO

TAP::Object,TAP::Parser,TAP::Parser::Source,TAP::Parser::Iterator,TAP::Parser::IteratorFactory,TAP::Parser::SourceHandler::Executable,TAP::Parser::SourceHandler::Perl,TAP::Parser::SourceHandler::File,TAP::Parser::SourceHandler::Handle,TAP::Parser::SourceHandler::RawTAP

Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.

The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.


[8]ページ先頭

©2009-2026 Movatter.jp