Alien-Selenium
view release on metacpan or search on metacpan
inc/Pod/Snippets.pm view on Meta::CPAN
=head1 NAME
Zero::Wing - For great justice!
=head1 SYNOPSIS
=for test "synopsis" begin
use Zero::Wing;
my $capitain = Zero::Wing->capitain;
=for test "synopsis" end
=cut
# ...
1;
=for metatests "synopsis POD" end
=head1 DESCRIPTION
This class is a very simple extension of L<Pod::Parser> that extracts
POD snippets from Perl code, and pretty-prints it so as to make it
useable from other Perl code. As demonstrated above, B<Pod::Snipets>
is immediately useful to test-driven-development nutcases who want to
put every single line of Perl code under test, including code that is
in the POD (typically a SYNOPSIS section). There are other uses, such
as storing a piece of information that is both human- and
machine-readable (eg an XML schema) simultaneously as documentation
and code.
=head2 Using Pod::Snippets for unit testing
The L</SYNOPSIS> demonstrates how to use B<Pod::Snippets> to grab a
piece of POD and execute it with L<perlfunc/eval>. This can readily
be done using your usual unit testing methodology, without too much
ajusting if any. This approach has some advantages over other
code-in-POD devices such as L<Pod::Tested> and L<Test::Inline>:
=over
=item *
There is no preprocessing step involved, hence no temp files and no
loss of hair in the debugger due to line renumbering.
=item *
Speaking of which, L</as_code> prepends an appropriate C<#line> if
possible, so you can single-step through your POD (yow!).
=back
The Pod-Snippets CPAN distribution consists of a single Perl file, and
has no dependencies besides what comes with a standard Perl 5.8.x. It
is therefore easy to embed into your own module so that your users
won't need to install B<Pod::Snippets> by themselves before running
your test suite. All that remains to do is to select the right
options to pass to L</load> as part of an appropriately named wrapper
function in your test library.
=head2 Snippet Syntax
B<Pod::Snippets> only deals with verbatim portions of the POD (that
is, as per L<perlpod>, paragraphs that start with whitespace at the
right) and custom markup starting with C<=for test>, C<=begin test> or
C<=end test>; it discards the rest (block text, actual Perl code,
character markup such as BE<lt>E<gt>, =head's and so on). The keyword
"test" in C<=for test> and C<=begin test> can be replaced with
whatever one wants, using the C<-markup> argument to L</load>.
Actually the default value is not even "test"; nonetheless let's
assume you are using "test" yourself for the remainder of this
discussion. The following metadata markup is recognized:
=over
=item B<=for test ignore>
Starts ignoring all POD whatsoever. Verbatim portions of the POD are
no longer stashed by B<Pod::Snippets> until remanded by a subsequent
C<=for test>.
=item B<=for test>
Cancels the effect of an ongoing C<=for test ignore> directive.
=item B<=for test "foo" begin>
=item B<=for test "foo" end>
These signal the start and end of a I<named> POD snippet, that can
later be fetched by name using L</named>. Unless countermanded by
appropriate parser options (see L</load>), named POD snippets can
nest freely (even badly).
=item B<=begin test>
=item B<=end test>
The POD between these markers will be seen by B<Pod::Snippets>, but
not by other POD formatters. Otherwise has no effect on the naming or
ignoring of snippets; in particular, if the contents of the section is
not in POD verbatim style, it still gets ignored.
=item B<=begin test "foo">
=item B<=end test "foo">
These have the exact same effect as C<=for test "foo" begin> and
C<=for test "foo" end>, except that other POD formatters will not see
the contents of the block.
=back
=head1 CONSTRUCTORS
=head2 load ($source, -opt1 => $val1, ...)
( run in 0.401 second using v1.01-cache-2.11-cpan-f6376fbd888 )