App-Prima-REPL
view release on metacpan or search on metacpan
bin/prima-repl view on Meta::CPAN
######################################
# A custom inputHistory Output class #
######################################
package PrimaX::InputHistory::Output::REPL;
# Thanks to the tied output, I can simply "print" results and they will
# go to the output widget
sub printout {
my $self = shift;
print @_;
}
sub newline_printout {
my $self = shift;
print "\n" if $output_column != 0;
print @_;
}
sub new { return bless {} }
###############
# Final items #
###############
package main;
eval 'require PDL::Version' if not defined $PDL::Version::VERSION;
# Print the opening message:
print "Welcome to the Prima REPL, version $version.\n";
print "Using PDL version $PDL::Version::VERSION\n" if ($loaded_PDL);
print "Using PDL::Graphics::Prima\n" if ($loaded_Prima_Graphics);
print "\n";
print join(' ', "If you don't know what you're doing, you can get help by"
, "typing 'help' and pressing Enter, or by pressing Ctrl-h.\n");
#################################
# Run any initialization script #
#################################
sub redo_initrc {
my $filename = $initrc_filename if -f $initrc_filename;
$filename = "$initrc_filename.pl" if -f "$initrc_filename.pl";
if ($filename) {
print "Running initialization script\n";
# Load the init script and send it to
open my $fh, '<', $filename;
my $text = do { local( $/ ) ; <$fh> };
my_eval("#line 1 \"$filename\"\n$text");
REPL::warn("Errors encountered running the initialization script:\n$@\n")
if $@;
$@ = '';
}
else {
print "No initialization script found\n";
}
}
redo_initrc if -f $initrc_filename or -f "$initrc_filename.pl";
run Prima;
# Remove the logfile. This will not happen with a system failure, which means
# that the logfile is 'saved' only when there was a problem. The special case of
# the user typing 'exit' at the prompt is handled in pressed_enter().
unlink 'prima-repl.logfile';
__END__
=head1 App::Prima::REPL Help
This is the help documentation for App::Prima::REPL, a graphical run-eval-print-loop
(REPL) for perl development, targeted at pdl users. Its focus is on L<PDL>, the
Perl Data Language, but it works just fine even if you don't have PDL.
At the bottom of the App::Prima::REPL window is a single entry line for direct
command input. The main window is a set of tabs, the first of which is an output
tab. Additional tabs can contain files or any other extension that has been
written as a App::Prima::REPL tab.
If your project has project-specific notes, you should be able to find them
either here: L<prima-repl.initrc> or here: L<prima-repl.initrc.pl>.
=head1 Fixing Documentation Fonts
If your documentation fonts look bad, you can change them by going to
View->Set Font Encoding.
=head1 Basic Navigation
Before I launch into the tutorial, I want to cover some basic navigation to help
you quickly get around the REPL. The following keyboard shortcuts should be
helpful to you even as we get started:
Normal Keyboard Mac Laptop
CTRL-h CTRL-h open or switch to the help window
ALT-1 ?????? go to the output window
CTRL-i CTRL-i put the cursor in the input line
CTRL-PageUp CTRL-FN-Up go to the previous tab
CTRL-PageDown CTRL-FN-Down go to the next tab
=head1 Tutorials
These are a collection of tutorials to get you started using the Prima REPL.
Except for the first tutorial, text that you should enter will be prefixed with
a prompt like C<< > >>.
=head2 Basic Output
Our first exercise will be getting basic output from the REPL. Enter the
following into the input line, but don't press enter yet:
print "Hello!"
Take note of the last line of text in the output window, then press enter.
You should see the following appear on your output screen:
> print "Hello!"
Hello!
What happens if you type an expression like 1+1? If you just type the expression
in the input line, you will see this as output:
> 1+1
Why didn't it print 2? It didn't print 2 because you didn't ask it to print 2.
You can easily accomplish that by using the C<print> function, or its
abbreviation C<p>. Type the following in the input line:
p 1+1
The output should look like this:
> p 1+1
2
You may be used to REPLs that print out the result of whatever action you just
took. This REPL does not do that because it is geared towards PDL use, and
the output for PDL can get exceedingly long. Rather than always print
potentially long results to the output, the Prima REPL is quiet by default and
makes it easy to print your results if you want.
=head2 Finding Documentation
Prima REPL uses Prima's built-in pod viewer (which you may be using to view this
documentation). If you have the help window open, you can look at a particular
module's documentation by pressing C<g> on your keyboard. A dialog will ask for
the name of the module with the documentation you want to read and will open
that module if it manages to find it.
There are two additional commands for finding and viewing help. The first is
the C<help> command. By itself, the C<help> command brings up the documentation
for Prima REPL. (Pressing C<CTRL-h> accomplishes the same thing.) However, you
can also specify the name of a module with documentation:
> help Carp
This command will open the pod viewer with the requested module's documentation.
This is sometimes preferable to pressing C<g> from Prima's help window, since
if you have a typo in your module name you must retype the whole thing. The
input line remembers what you last typed, so it's easy to retrieve the
correct typos.
If you have PDL, you can also use the C<pdldoc> command, which operates
similarly to the C<pdldoc> program on your computer. Typing
( run in 1.054 second using v1.01-cache-2.11-cpan-6aa56a78535 )