NAME
Pod::Tests - Extracts embedded tests and code examples from POD
SYNOPSIS
LOOK AT pod2test FIRST!
use Pod::Tests;
$p->new;
$p->parse_file($file);
$p->parse_fh($fh);
$p->parse(@code);
my @examples = $p->examples;
my @tests = $p->tests;
foreach my $example (@examples) {
print "The example: '$example->{code}' was on line ".
"$example->{line}\n";
}
DESCRIPTION
LOOK AT pod2test FIRST! THIS IS ALPHA CODE!
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.
Embedded Tests
Embedding tests allows tests to be placed near the code its testing. This is a nice supplement to the traditional .t files.
A test is denoted using either "=for testing" or a "=begin/end testing" block.
=item B<is_pirate>
@pirates = is_pirate(@arrrgs);
Go through @arrrgs and return a list of pirates.
=begin testing
my @p = is_pirate('Blargbeard', 'Alfonse', 'Capt. Hampton', 'Wesley');
ok(@p == 2);
=end testing
=cut
sub is_pirate {
....
}
Code Examples EXPERIMENTAL
BIG FAT WARNING perldoc and the various pod2* reformatters are inconsistant in how they deal with =also. Some warn, some display it, some choke. So consider this to be a Highly Experimental Feature.
Code examples in documentation are rarely tested. Pod::Tests provides a way to do some minimalist testing of your examples.
A code example is denoted using either "=also for example" or an "=also begin/end example" block.
The =also
tag provides that examples will both be extracted and displayed as documentation.
=also for example
print "Here is a fine example of something or other.";
=also begin example
use LWP::Simple;
getprint "http://www.goats.com";
=also end example
Formatting
The code examples and embedded tests are not translated from POD, thus all the C<> and B<> style escapes are not valid. Its literal Perl code.
Methods
- new
-
$parser = Pod::Tests->new;
Returns a new Pod::Tests object which lets you read tests and examples out of a POD document.
- parse
-
$parser->parse(@code);
Finds the examples and tests in a bunch of lines of Perl @code. Once run they're available via examples() and testing().
- parse_fh
- parse_file
-
$parser->parse_file($filename); $parser->parse_fh($fh);
Just like parse() except it works on a file or a filehandle, respectively.
- examples
- testing
-
@examples = $parser->examples; @testing = $parser->tests;
Returns the examples and tests found in the parsed POD documents. Each element of @examples and @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
NOTE In the future, these will become full-blown objects.
AUTHOR
Michael G Schwern <schwern@pobox.com>
NOTES and CAVEATS
This module is currently EXPERIMENTAL and only for use by pod2test. If you use it, the interface will change from out from under you.
It currently does not use Pod::Parser. The thing is too complicated, I couldn't figure out how to use it. Instead, I use a simple, home-rolled parser. This will eventually be split out as Pod::Parser::Simple.
SEE ALSO
pod2test, Perl 6 RFC 183 http://dev.perl.org/rfc183.pod
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 317:
You forgot a '=back' before '=head1'