Demos.pm (PDL-2.082) | : | Demos.pm (PDL-2.083) | ||
---|---|---|---|---|
skipping to change at line 149 | skipping to change at line 149 | |||
no strict; | no strict; | |||
PDL::Demos->init($_[0]); | PDL::Demos->init($_[0]); | |||
$_->[0]->($_->[1]) for PDL::Demos->demo($_[0]); | $_->[0]->($_->[1]) for PDL::Demos->demo($_[0]); | |||
PDL::Demos->done($_[0]); | PDL::Demos->done($_[0]); | |||
} | } | |||
=head1 DESCRIPTION | =head1 DESCRIPTION | |||
Provides utilities to make demos for PDL modules. | Provides utilities to make demos for PDL modules. | |||
PDL demos should be in the C<PDL::Demos::*> namespace so that they can | ||||
be auto-discovered. | ||||
Please ensure that your demo module is included in a CPAN distribution | ||||
and add it to the appropriate metadata (e.g. C<Makefile.PL> and | ||||
C<MANIFEST>). | ||||
=head1 METHODS | =head1 METHODS | |||
=head2 list | =head2 list | |||
Class method; goes through C<@INC> finding all modules starting with | Class method; goes through C<@INC> finding all modules starting with | |||
C<PDL::Demos::> (with up to two C<::>-separated words). Cached after | C<PDL::Demos::> (with up to two C<::>-separated words). Cached after | |||
first run. Does not distinguish demo modules that did not load. | first run. Does not distinguish demo modules that did not load. | |||
=head2 keywords | =head2 keywords | |||
skipping to change at line 192 | skipping to change at line 199 | |||
module if it has one, or throws exception if unknown keyword. | module if it has one, or throws exception if unknown keyword. | |||
=head1 DEMO MODULE METHODS | =head1 DEMO MODULE METHODS | |||
Each demo module must provide these class methods: | Each demo module must provide these class methods: | |||
=over | =over | |||
=item info | =item info | |||
Return a two-element list: a single keyword (probably lower-case), | Return a two-element list of strings: a single keyword (probably | |||
and a short description of the demo. | lower-case), and a short description of the demo. Both will be displayed | |||
when a user enters C<demo> without giving a name. | ||||
=item demo | =item demo | |||
Returns a list of array-refs of two elements: a function provided by this | Returns a list of array-refs of two elements: a L<function|/FUNCTIONS> | |||
module, and an argument for it. | provided by this module, and an argument for it. | |||
=item init | =item init | |||
Return a string which will be evaluated in the package running the | Return a string of Perl code which will be evaluated in the package | |||
demo. Use this for C<use> statements that import functions needed in | running the demo. Use this e.g. for C<use> statements that import | |||
your demo. | functions needed in your demo. | |||
=back | =back | |||
=head1 FUNCTIONS | =head1 FUNCTIONS | |||
These are all exported. | These are all exported. | |||
=head2 comment | =head2 comment | |||
Prints its argument, prompts user to press enter before returning. | Prints its argument, prompts user to press enter before returning. | |||
=head2 output | =head2 output | |||
Prints its argument (best for use in C<actnw> etc). | Prints its argument (best for use in C<actnw> etc). | |||
=head2 actnw | =head2 actnw | |||
Prints its argument with a separator, then evaluates it as Perl code | The argument must be a string containing valid Perl code. The string | |||
with C<PDL> loaded. Doesn't prompt, so use this for e.g. GUI demos that | is printed with a separator, then evaluated as Perl code in the | |||
return when the user tells them to. | package running the demo, with C<PDL> loaded. Doesn't prompt, so use | |||
this for e.g. GUI demos that return when the user tells them to. | ||||
Multiline code string should start with a newline. | ||||
=head2 act | =head2 act | |||
As above, but prompts before returning. | As above, but prompts before returning. | |||
=head1 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 | ||||
C<init> 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. | ||||
If you want to show the demo in the overview though it can't run in | ||||
the current situation, then make sure that your C<demo> method informs | ||||
the user what is missing, and where they can obtain it. | ||||
=head1 AUTHOR | =head1 AUTHOR | |||
Copyright (C) 1998 Tuomas J. Lukka. | Copyright (C) 1998 Tuomas J. Lukka. | |||
Tweaks by Ed J for PDL 2.077, 2022. | Tweaks by Ed J for PDL 2.077, 2022. | |||
=cut | =cut | |||
1; | 1; | |||
End of changes. 6 change blocks. | ||||
10 lines changed or deleted | 35 lines changed or added |