.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Demos 3pm" .TH Demos 3pm 2024-04-22 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME PDL::Demos \- PDL demo infrastructure .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 10 \& # in a demo, if text\-orientated \& package PDL::Demos::Blah; \& sub info { (\*(Aqblah\*(Aq, \*(AqLonger description of demo\*(Aq) } \& sub init { \*(Aquse PDL::Graphics::PGPLOT;\*(Aq } \& my @demo = ( \& [comment => "Welcome to the Blah demo"], \& [act => <<\*(AqEOF\*(Aq], \& output "PDL can make n\-dimensional sequences:\en"; \& output $x = sequence(2,3); \& EOF \& ); \& sub demo { @demo } \& sub done { "# return things to previous state\en" } \& \& # a GUI\-orientated one \& package PDL::Demos::GUIBlah; \& use GUIBlah; # so demo won\*(Aqt show up in list if GUIBlah not installed \& sub info { (\*(Aqblahgui\*(Aq, \*(AqGUIBlah demo\*(Aq) } \& sub demo {[actnw => q| \& # starting up the GUI demo app \& |._\|_PACKAGE_\|_.q|::run(); \& |]} \& sub run { # this is just a convention, but a good one \& # ... \& } \& \& # iterate a demo of your own module \- call it PDL::Demos::(something) \& make && perl \-Mblib \-S perldl # run "demo" and it will see your demo \& \& # in a CLI or REPL \& use PDL::Demos; \& sub demo { \& if (!$_[0]) { \& require List::Util; \& my @kw = sort grep $_ ne \*(Aqpdl\*(Aq, PDL::Demos\->keywords; \& my $maxlen = List::Util::max(map length, @kw); \& print "Use:\en"; \& printf " demo %\-${maxlen}s # %s\en", @$_[0,1] for map [PDL::Demos\->info($_)], \*(Aqpdl\*(Aq, @kw; \& return; \& } \& no strict; \& PDL::Demos\->init($_[0]); \& $_\->[0]\->($_\->[1]) for PDL::Demos\->demo($_[0]); \& PDL::Demos\->done($_[0]); \& } .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Provides utilities to make demos for PDL modules. .PP PDL demos should be in the \f(CW\*(C`PDL::Demos::*\*(C'\fR namespace so that they can be auto-discovered. .PP Please ensure that your demo module is included in a CPAN distribution and add it to the appropriate metadata (e.g. \f(CW\*(C`Makefile.PL\*(C'\fR and \&\f(CW\*(C`MANIFEST\*(C'\fR). .SH METHODS .IX Header "METHODS" .SS list .IX Subsection "list" Class method; goes through \f(CW@INC\fR finding all modules starting with \&\f(CW\*(C`PDL::Demos::\*(C'\fR (with up to two \f(CW\*(C`::\*(C'\fR\-separated words). Cached after first run. Does not distinguish demo modules that did not load. .SS keywords .IX Subsection "keywords" Returns the list of keywords (first element of \f(CW\*(C`info\*(C'\fR return-list) of all found modules that loaded successfully and implement an \f(CW\*(C`info\*(C'\fR method. Caches results. .SS info .IX Subsection "info" Given a keyword, returns the result of calling \f(CW\*(C`info\*(C'\fR on the relevant module plus the module name (three elements) or throws exception if unknown keyword. .SS init .IX Subsection "init" Given a keyword, \f(CW\*(C`eval\*(C'\fRs the result of calling \f(CW\*(C`init\*(C'\fR on the relevant module if it has one, or throws exception if unknown keyword. .SS demo .IX Subsection "demo" Given a keyword, returns the result of calling \f(CW\*(C`demo\*(C'\fR on the relevant module or throws exception if unknown keyword. .SS done .IX Subsection "done" Given a keyword, \f(CW\*(C`eval\*(C'\fRs the result of calling \f(CW\*(C`done\*(C'\fR on the relevant module if it has one, or throws exception if unknown keyword. .SH "DEMO MODULE METHODS" .IX Header "DEMO MODULE METHODS" Each demo module must provide these class methods: .IP info 4 .IX Item "info" Return a two-element list of strings: a single keyword (probably lower-case), and a short description of the demo. Both will be displayed when a user enters \f(CW\*(C`demo\*(C'\fR without giving a name. .IP demo 4 .IX Item "demo" Returns a list of array-refs of two elements: a function provided by this module, and an argument for it. .IP init 4 .IX Item "init" Return a string of Perl code which will be evaluated in the package running the demo. Use this e.g. for \f(CW\*(C`use\*(C'\fR statements that import functions needed in your demo. .SH FUNCTIONS .IX Header "FUNCTIONS" These are all exported. .SS comment .IX Subsection "comment" Prints its argument, prompts user to press enter before returning. .SS output .IX Subsection "output" Prints its argument (best for use in \f(CW\*(C`actnw\*(C'\fR etc). .SS actnw .IX Subsection "actnw" The argument must be a string containing valid Perl code. The string is printed with a separator, then evaluated as Perl code in the package running the demo, with \f(CW\*(C`PDL\*(C'\fR loaded. Doesn't prompt, so use this for e.g. GUI demos that return when the user tells them to. .PP Multiline code string should start with a newline. .SS act .IX Subsection "act" As above, but prompts before returning. .SH "ERROR HANDLING" .IX Header "ERROR HANDLING" Check the prerequisites (e.g. optional Perl modules) for your demo in your demo module and not only in the code string you pass to the \&\f(CW\*(C`init\*(C'\fR routine. If the code in your demo module dies, then the demo will not be offered in the demo overview. Fatal errors in the init routine will be printed and mess up the output layout. Also, error messages might be difficult to understand if users just want to run the demo. .PP If you want to show the demo in the overview though it can't run in the current situation, then make sure that your \f(CW\*(C`demo\*(C'\fR method informs the user what is missing, and where they can obtain it. .SH AUTHOR .IX Header "AUTHOR" Copyright (C) 1998 Tuomas J. Lukka. Tweaks by Ed J for PDL 2.077, 2022.