Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages

Manual Reference Pages  -  POD::TESTS (3)

.ds Aq ’


Pod::Tests - Extracts embedded tests and code examples from POD



  use Pod::Tests;
  $p = Pod::Tests->new;


  my @examples = $p->examples;
  my @tests    = $p->tests;

  foreach my $example (@examples) {
      print "The example:  $example->{code} was on line ".

  my @test_code         = $p->build_tests(@tests);
  my @example_test_code = $p->build_examples(@examples);


This is a specialized POD viewer to extract embedded tests and code examples from POD. It doesn’t do much more than that. pod2test does the useful work.


After creating a Pod::Tests object, you parse the POD by calling one of the available parsing methods documented below. You can call parse as many times as you’d like, all examples and tests found will stack up inside the object.


Once extracted, the tests can be built into stand-alone testing code using the build_tests() and build_examples() methods. However, it is recommended that you first look at the pod2test program before embarking on this.



  $parser = Pod::Tests->new;

Returns a new Pod::Tests object which lets you read tests and examples out of a POD document.



Finds the examples and tests in a bunch of lines of Perl @code. Once run they’re available via examples() and testing().

parse_file CW$file


Just like parse() except it works on a file.

parse_fh CW$fh


Just like parse() except it works on a filehandle.


  @testing  = $parser->tests;

Returns the tests found in the parsed POD documents. Each element of @testing is a hash representing an individual testing block and contains information about that block.

  $test->{code}         actual testing code
  $test->{line}         line from where the test was taken


  @examples = $parser->examples;

Returns the examples found in the parsed POD documents. Each element of @examples is a hash representing an individual testing block and contains information about that block.

  $test->{code}         actual testing code
  $test->{line}         line from where the test was taken


  my @code = $p->build_tests(@tests);

Returns a code fragment based on the given embedded @tests. This fragment is expected to print the usual ok/not ok (or something Test::Harness can read) or nothing at all.

Typical usage might be:

    my @code = $p->build_tests($p->tests);

This fragment is suitable for placing into a larger test script.

<B>NOTEB> Look at pod2test before embarking on your own test building.


  my @code = $p->build_examples(@examples);

Similar to build_tests(), it creates a code fragment which tests the basic validity of your example code. Essentially, it just makes sure it compiles.

If your example has an example testing block associated with it it will run the the example code and the example testing block.


Here’s the simplest example, just finding the tests and examples in a single module.

  my $p = Pod::Tests->new;

And one to find all the tests and examples in a directory of files. This illustrates building a set of examples and tests through multiple calls to parse_file().

  my $p = Pod::Tests->new;
  opendir(PODS, "path/to/some/lib/") || die $!;
  while( my $file = readdir PODS ) {
  printf "Found %d examples and %d tests in path/to/some/lib\n",
         scalar $p->examples, scalar $p->tests;

Finally, an example of parsing your own POD using the DATA filehandle.

  use Fcntl qw(:seek);
  my $p = Pod::Tests->new;

  # Seek to the beginning of the current code.
  seek(DATA, 0, SEEK_SET) || die $!;


This module has been replaced by the newer Test::Inline 2. Most testing code that currently works with pod2test should continue to work with the new version. The most notable exceptions are =for begin and =for end, which are deprecated.

After upgrading, Pod::Tests and pod2test were split out to provide a compatibility package for legacy code.

pod2test will stay in CPAN, but should remain unchanged indefinately, with the exception of any minor bugs that will require squishing.

Bugs in this dist should be reported via the following URL. Feature requests should not be submitted, as further development is now occuring in Test::Inline.



Michael G Schwern <>

Adam Kennedy <>



pod2test, Perl 6 RFC 183

Short set of slides on Pod::Tests

Similar schemes can be found in SelfTest and Test::Unit.


Copyright 2005 - 2008 Adam Kennedy.

Copyright 2001 - 2003 Michael G Schwern.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

Search for    or go to Top of page |  Section 3 |  Main Index

perl v5.20.3 POD::TESTS (3) 2008-07-13

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.