TAP::Parser::SourceHandler



TAP::Parser::SourceHandler

NAME
VERSION
SYNOPSIS
DESCRIPTION
METHODS
SUBCLASSING
AUTHORS
SEE ALSO

NAME

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

VERSION

Version 3.23

SYNOPSIS

  # abstract class − don't use directly!
  # see TAP::Parser::IteratorFactory for general usage
  # must be sub−classed for use
  package MySourceHandler;
  use base qw( 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 for TAP::Parser::Source handlers / handlers.

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

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

Unless you’re writing a new TAP::Parser::SourceHandler, a plugin, or subclassing TAP::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 a TAP::Parser::Source.

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.

"make_iterator"

Abstract method.

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

$source is a TAP::Parser::Source.

Returns a new TAP::Parser::Iterator object for use by the TAP::Parser. "croak"s 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 with TAP::Parser::Source and TAP::Parser::IteratorFactory. TAP::Parser::SourceHandler::RawTAP is the easiest sub-class to use an an example.

It’s important to point out that if you want your subclass to be automatically used by TAP::Parser you’ll have to and make sure it gets loaded somehow. If you’re using prove you can write an App::Prove plugin. If you’re using TAP::Parser or TAP::Harness directly (e.g. through a custom script, ExtUtils::MakeMaker, or Module::Build) you can use the "config" 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 vars '@ISA'; # compat with older perls
  use MySourceHandler; # see TAP::Parser::SourceHandler
  use TAP::Parser::IteratorFactory;
  @ISA = qw( 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






Opportunity


Personal Opportunity - Free software gives you access to billions of dollars of software at no cost. Use this software for your business, personal use or to develop a profitable skill. Access to source code provides access to a level of capabilities/information that companies protect though copyrights. Open source is a core component of the Internet and it is available to you. Leverage the billions of dollars in resources and capabilities to build a career, establish a business or change the world. The potential is endless for those who understand the opportunity.

Business Opportunity - Goldman Sachs, IBM and countless large corporations are leveraging open source to reduce costs, develop products and increase their bottom lines. Learn what these companies know about open source and how open source can give you the advantage.





Free Software


Free Software provides computer programs and capabilities at no cost but more importantly, it provides the freedom to run, edit, contribute to, and share the software. The importance of free software is a matter of access, not price. Software at no cost is a benefit but ownership rights to the software and source code is far more significant.


Free Office Software - The Libre Office suite provides top desktop productivity tools for free. This includes, a word processor, spreadsheet, presentation engine, drawing and flowcharting, database and math applications. Libre Office is available for Linux or Windows.





Free Books


The Free Books Library is a collection of thousands of the most popular public domain books in an online readable format. The collection includes great classical literature and more recent works where the U.S. copyright has expired. These books are yours to read and use without restrictions.


Source Code - Want to change a program or know how it works? Open Source provides the source code for its programs so that anyone can use, modify or learn how to write those programs themselves. Visit the GNU source code repositories to download the source.





Education


Study at Harvard, Stanford or MIT - Open edX provides free online courses from Harvard, MIT, Columbia, UC Berkeley and other top Universities. Hundreds of courses for almost all major subjects and course levels. Open edx also offers some paid courses and selected certifications.


Linux Manual Pages - A man or manual page is a form of software documentation found on Linux/Unix operating systems. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts.