Pod::ToDemo - writes a demo program from a tutorial POD
use Pod::ToDemo <<'END_HERE'; print "Hi, here is my demo program!\n"; END_HERE
Pod::ToDemo allows you to write POD-only modules that serve as tutorials which can write out demo programs if they're invoked directly. That is, while SDL::Tutorial is a tutorial on writing beginner SDL applications with Perl, you can invoke it as:
$ perl -MSDL::Tutorial=sdl_demo.pl -e 1
and it will write a bare-bones demo program called sdl_demo.pl based on the tutorial.
sdl_demo.pl
Call Pod::ToDemo::write_demo() with two arguments. $filename is the name of the file to write. If there's no name, this function will die() with an error message. If a file already exists with this name, this function will also die() with another error message. The second argument, $demo, is the text of the demo program to write.
Pod::ToDemo::write_demo()
$filename
die()
$demo
If you're using this in tutorial modules, as you should be, you will probably want to protect programs that inadvertently use the tutorial from attempting to write demo files. Pod::ToDemo does this automatically for you by checking that you haven't invoked the tutorial module from the command line.
To prevent perl from interpreting the name of the file to write as the name of a file to invoke (a file which does not yet exist), you must pass the name of the file on the command line as an argument to the tutorial module's import() method. If this doesn't make sense to you, just remember to tell people to write:
import()
$ perl -MTutorial::Module=I<file_to_write.pl> -e 1
chromatic, <chromatic at wgz dot org>
No known bugs, now. Thanks to Greg Lapore for helping me track down a bug in 0.10 and to rrwo for Windows test tweaks.
Copyright (c) 2003 - 2004, chromatic. All rights reserved. This module is distributed under the same terms as Perl itself, in the hope that it is useful but certainly under no guarantee.
To install Pod::ToDemo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pod::ToDemo
CPAN shell
perl -MCPAN -e shell install Pod::ToDemo
For more information on module installation, please visit the detailed CPAN module installation guide.