1Demos(3)              User Contributed Perl Documentation             Demos(3)
2
3
4

NAME

6       PDL::Demos - PDL demo infrastructure
7

SYNOPSIS

9         # in a demo, if text-orientated
10         package PDL::Demos::Blah;
11         sub info { ('blah', 'Longer description of demo') }
12         sub init { 'use PDL::Graphics::PGPLOT;' }
13         my @demo = (
14           [comment => "Welcome to the Blah demo"],
15           [act => <<'EOF'],
16         output "PDL can make n-dimensional sequences:\n";
17         output $x = sequence(2,3);
18         EOF
19         );
20         sub demo { @demo }
21         sub done { "# return things to previous state\n" }
22
23         # a GUI-orientated one
24         package PDL::Demos::GUIBlah;
25         use GUIBlah; # so demo won't show up in list if GUIBlah not installed
26         sub info { ('blahgui', 'GUIBlah demo') }
27         sub demo {[actnw => q|
28           # starting up the GUI demo app
29           |.__PACKAGE__.q|::run();
30         |]}
31         sub run { # this is just a convention, but a good one
32           # ...
33         }
34
35         # iterate a demo of your own module - call it PDL::Demos::(something)
36         make && perl -Mblib -S perldl # run "demo" and it will see your demo
37
38         # in a CLI or REPL
39         use PDL::Demos;
40         sub demo {
41           if (!$_[0]) {
42             require List::Util;
43             my @kw = sort grep $_ ne 'pdl', PDL::Demos->keywords;
44             my $maxlen = List::Util::max(map length, @kw);
45             print "Use:\n";
46             printf "   demo %-${maxlen}s # %s\n", @$_[0,1] for map [PDL::Demos->info($_)], 'pdl', @kw;
47             return;
48           }
49           no strict;
50           PDL::Demos->init($_[0]);
51           $_->[0]->($_->[1]) for PDL::Demos->demo($_[0]);
52           PDL::Demos->done($_[0]);
53         }
54

DESCRIPTION

56       Provides utilities to make demos for PDL modules.
57

METHODS

59   list
60       Class method; goes through @INC finding all modules starting with
61       "PDL::Demos::" (with up to two "::"-separated words). Cached after
62       first run. Does not distinguish demo modules that did not load.
63
64   keywords
65       Returns the list of keywords (first element of "info" return-list) of
66       all found modules that loaded successfully and implement an "info"
67       method. Caches results.
68
69   info
70       Given a keyword, returns the result of calling "info" on the relevant
71       module plus the module name (three elements) or throws exception if
72       unknown keyword.
73
74   init
75       Given a keyword, "eval"s the result of calling "init" on the relevant
76       module if it has one, or throws exception if unknown keyword.
77
78   demo
79       Given a keyword, returns the result of calling "demo" on the relevant
80       module or throws exception if unknown keyword.
81
82   done
83       Given a keyword, "eval"s the result of calling "done" on the relevant
84       module if it has one, or throws exception if unknown keyword.
85

DEMO MODULE METHODS

87       Each demo module must provide these class methods:
88
89       info
90           Return a two-element list: a single keyword (probably lower-case),
91           and a short description of the demo.
92
93       demo
94           Returns a list of array-refs of two elements: a function provided
95           by this module, and an argument for it.
96
97       init
98           Return a string which will be evaluated in the package running the
99           demo. Use this for "use" statements that import functions needed in
100           your demo.
101

FUNCTIONS

103       These are all exported.
104
105   comment
106       Prints its argument, prompts user to press enter before returning.
107
108   output
109       Prints its argument (best for use in "actnw" etc).
110
111   actnw
112       Prints its argument with a separator, then evaluates it as Perl code
113       with "PDL" loaded. Doesn't prompt, so use this for e.g. GUI demos that
114       return when the user tells them to.
115
116   act
117       As above, but prompts before returning.
118

AUTHOR

120       Copyright (C) 1998 Tuomas J. Lukka.  Tweaks by Ed J for PDL 2.077,
121       2022.
122
123
124
125perl v5.36.0                      2023-01-20                          Demos(3)
Impressum