document the optional features
[p5sagit/Devel-REPL.git] / README.md
CommitLineData
80bc1543 1# NAME
2
3Devel::REPL - a modern perl interactive shell
4
5# SYNOPSIS
6
7 my $repl = Devel::REPL->new;
8 $repl->load_plugin($_) for qw(History LexEnv);
9 $repl->run
10
11Alternatively, use the 're.pl' script installed with the distribution
12
13 system$ re.pl
14
15# DESCRIPTION
16
17This is an interactive shell for Perl, commonly known as a REPL - Read,
18Evaluate, Print, Loop. The shell provides for rapid development or testing
19of code without the need to create a temporary source code file.
20
21Through a plugin system, many features are available on demand. You can also
22tailor the environment through the use of profiles and run control files, for
23example to pre-load certain Perl modules when working on a particular project.
24
25# USAGE
26
27To start a shell, follow one of the examples in the ["SYNOPSIS"](#SYNOPSIS) above.
28
29Once running, the shell accepts and will attempt to execute any code given. If
30the code executes successfully you'll be shown the result, otherwise an error
31message will be returned. Here are a few examples:
32
33 $_ print "Hello, world!\n"
34 Hello, world!
35 1
36 $_ nosuchfunction
37 Compile error: Bareword "nosuchfunction" not allowed while "strict subs" in use at (eval 130) line 5.
38
39 $_
40
41In the first example above you see the output of the command (`Hello,
42world!`), if any, and then the return value of the statement (`1`). Following
43that example, an error is returned when the execution of some code fails.
44
45Note that the lack of semicolon on the end is not a mistake - the code is
46run inside a Block structure (to protect the REPL in case the code blows up),
47which means a single statement doesn't require the semicolon. You can add one
48if you like, though.
49
50If you followed the first example in the ["SYNOPSIS"](#SYNOPSIS) above, you'll have the
51History and LexEnv plugins loaded (and there are many more available).
52Although the shell might support "up-arrow" history, the History plugin adds
53"bang" history to that so you can re-execute chosen commands (with e.g.
54`!53`). The LexEnv plugin ensures that lexical variables declared with the
55`my` keyword will automatically persist between statements executed in the
56REPL shell.
57
58When you `use` any Perl module, the `import()` will work as expected - the
59exported functions from that module are available for immediate use:
60
61 $_ carp "I'm dieeeing!\n"
62 String found where operator expected at (eval 129) line 5, near "carp "I'm dieeeing!\n""
63 (Do you need to predeclare carp?)
64 Compile error: syntax error at (eval 129) line 5, near "carp "I'm dieeeing!\n""
65 BEGIN not safe after errors--compilation aborted at (eval 129) line 5.
66
67 $_ use Carp
68
69 $_ carp "I'm dieeeing!\n"
70 I'm dieeeing!
71 at /usr/share/perl5/Lexical/Persistence.pm line 327
72 1
73 $_
74
75To quit from the shell, hit `Ctrl+D` or `Ctrl+C`.
76
77 MSWin32 NOTE: control keys won't work if TERM=dumb
78 because readline functionality will be disabled.
79
80
81
82## Run Control Files
83
84For particular projects you might well end up running the same commands each
85time the REPL shell starts up - loading Perl modules, setting configuration,
86and so on. A run control file lets you have this done automatically, and you
87can have multiple files for different projects.
88
89By default the `re.pl` program looks for `$HOME/.re.pl/repl.rc`, and
90runs whatever code is in there as if you had entered it at the REPL shell
91yourself.
92
93To set a new run control file that's also in that directory, pass it as a
94filename like so:
95
96 system$ re.pl --rcfile myproject.pc
97
e962ffaa 98If the filename happens to contain a forward slash, then it's used absolutely,
80bc1543 99or realive to the current working directory:
100
101 system$ re.pl --rcfile /path/to/my/project/repl.rc
102
103Within the run control file you might want to load plugins. This is covered in
104["The REPL shell object"](#The REPL shell object) section, below.
105
106## Profiles
107
108To allow for the sharing of run control files, you can fashion them into a
109Perl module for distribution (perhaps via the CPAN). For more information on
110this feature, please see the [Devel::REPL::Profile](http://search.cpan.org/perldoc?Devel::REPL::Profile) manual page.
111
112A default profile ships with `Devel::REPL`; it loads the following plugins:
113
114- [Devel::REPL::Plugin::History](http://search.cpan.org/perldoc?Devel::REPL::Plugin::History)
115- [Devel::REPL::Plugin::LexEnv](http://search.cpan.org/perldoc?Devel::REPL::Plugin::LexEnv)
116- [Devel::REPL::Plugin::DDS](http://search.cpan.org/perldoc?Devel::REPL::Plugin::DDS)
117- [Devel::REPL::Plugin::Packages](http://search.cpan.org/perldoc?Devel::REPL::Plugin::Packages)
118- [Devel::REPL::Plugin::Commands](http://search.cpan.org/perldoc?Devel::REPL::Plugin::Commands)
119- [Devel::REPL::Plugin::MultiLine::PPI](http://search.cpan.org/perldoc?Devel::REPL::Plugin::MultiLine::PPI)
120- [Devel::REPL::Plugin::Colors](http://search.cpan.org/perldoc?Devel::REPL::Plugin::Colors)
121- [Devel::REPL::Plugin::Completion](http://search.cpan.org/perldoc?Devel::REPL::Plugin::Completion)
122- [Devel::REPL::Plugin::CompletionDriver::INC](http://search.cpan.org/perldoc?Devel::REPL::Plugin::CompletionDriver::INC)
123- [Devel::REPL::Plugin::CompletionDriver::LexEnv](http://search.cpan.org/perldoc?Devel::REPL::Plugin::CompletionDriver::LexEnv)
124- [Devel::REPL::Plugin::CompletionDriver::Keywords](http://search.cpan.org/perldoc?Devel::REPL::Plugin::CompletionDriver::Keywords)
125- [Devel::REPL::Plugin::CompletionDriver::Methods](http://search.cpan.org/perldoc?Devel::REPL::Plugin::CompletionDriver::Methods)
126- [Devel::REPL::Plugin::ReadlineHistory](http://search.cpan.org/perldoc?Devel::REPL::Plugin::ReadlineHistory)
127
128## Plugins
129
e962ffaa 130Plugins are a way to add functionality to the REPL shell, and take advantage of
80bc1543 131`Devel::REPL` being based on the [Moose](http://search.cpan.org/perldoc?Moose) object system for Perl 5. This
132means it's simple to 'hook into' many steps of the R-E-P-L process. Plugins
133can change the way commands are interpreted, or the way their results are
134output, or even add commands to the shell environment.
135
136A number of plugins ship with `Devel::REPL`, and more are available on the
137CPAN. Some of the shipped plugins are loaded in the default profile, mentioned
138above. These plugins can be loaded in your `$HOME/.re.pl/repl.rc` like:
139
140 load_plugin qw( CompletionDriver::Global DumpHistory );
141
142Writing your own plugins is not difficult, and is discussed in the
143[Devel::REPL::Plugin](http://search.cpan.org/perldoc?Devel::REPL::Plugin) manual page, along with links to the manual pages of
144all the plugins shipped with `Devel::REPL`.
145
146## The REPL shell object
147
148From time to time you'll want to interact with or manipulate the
149`Devel::REPL` shell object itself; that is, the instance of the shell you're
150currently running.
151
152The object is always available through the `$_REPL` variable. One common
153requirement is to load an additional plugin, after your profile and run
154control files have already been executed:
155
156 $_ $_REPL->load_plugin('Timing');
157 1
158 $_ print "Hello again, world!\n"
159 Hello again, world!
160 Took 0.00148296356201172 seconds.
161 1
162 $_
163
164# REQUIREMENTS
165
166In addition to the contents of the standard Perl distribution, you will need
167the following:
168
169- [Moose](http://search.cpan.org/perldoc?Moose) >= 0.74
170- [MooseX::Object::Pluggable](http://search.cpan.org/perldoc?MooseX::Object::Pluggable) >= 0.0009
171- [MooseX::Getopt](http://search.cpan.org/perldoc?MooseX::Getopt) >= 0.18
172- [namespace::autoclean](http://search.cpan.org/perldoc?namespace::autoclean)
173- [File::HomeDir](http://search.cpan.org/perldoc?File::HomeDir)
174- [Task::Weaken](http://search.cpan.org/perldoc?Task::Weaken)
175- [B::Concise](http://search.cpan.org/perldoc?B::Concise)
176- [Term::ANSIColor](http://search.cpan.org/perldoc?Term::ANSIColor)
177- [Devel::Peek](http://search.cpan.org/perldoc?Devel::Peek)
178
179Optionally, some plugins if installed will require the following modules:
180
181- [PPI](http://search.cpan.org/perldoc?PPI)
182- [Data::Dump::Streamer](http://search.cpan.org/perldoc?Data::Dump::Streamer)
183- [Data::Dumper::Concise](http://search.cpan.org/perldoc?Data::Dumper::Concise)
184- [File::Next](http://search.cpan.org/perldoc?File::Next)
185- [Sys::SigAction](http://search.cpan.org/perldoc?Sys::SigAction)
186- [B::Keywords](http://search.cpan.org/perldoc?B::Keywords)
187- [Lexical::Persistence](http://search.cpan.org/perldoc?Lexical::Persistence)
188- [App::Nopaste](http://search.cpan.org/perldoc?App::Nopaste)
189- [Module::Refresh](http://search.cpan.org/perldoc?Module::Refresh)
190
191# AUTHOR
192
193Matt S Trout - mst (at) shadowcatsystems.co.uk ([http://www.shadowcatsystems.co.uk/](http://www.shadowcatsystems.co.uk/))
194
195# CONTRIBUTORS
196
197- Stevan Little - stevan (at) iinteractive.com
198- Alexis Sukrieh - sukria+perl (at) sukria.net
199- epitaph
200- mgrimes - mgrimes (at) cpan dot org
201- Shawn M Moore - sartak (at) gmail.com
202- Oliver Gorwits - oliver on irc.perl.org
203- Andrew Moore - `<amoore@cpan.org>`
204- Norbert Buchmuller `<norbi@nix.hu>`
205- Dave Houston `<dhouston@cpan.org>`
206- Chris Marshall
207- Karen Etheridge `<ether@cpan.org>`
208
209# LICENSE
210
211This library is free software under the same terms as perl itself