fix version requirement
[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
b76bf9f6 112A `Standard` profile ships with `Devel::REPL`; it loads the following plugins
113(note that some of these require optional features -- or you can also use the
114`Minimal` profile):
80bc1543 115
116- [Devel::REPL::Plugin::History](http://search.cpan.org/perldoc?Devel::REPL::Plugin::History)
117- [Devel::REPL::Plugin::LexEnv](http://search.cpan.org/perldoc?Devel::REPL::Plugin::LexEnv)
118- [Devel::REPL::Plugin::DDS](http://search.cpan.org/perldoc?Devel::REPL::Plugin::DDS)
119- [Devel::REPL::Plugin::Packages](http://search.cpan.org/perldoc?Devel::REPL::Plugin::Packages)
120- [Devel::REPL::Plugin::Commands](http://search.cpan.org/perldoc?Devel::REPL::Plugin::Commands)
121- [Devel::REPL::Plugin::MultiLine::PPI](http://search.cpan.org/perldoc?Devel::REPL::Plugin::MultiLine::PPI)
122- [Devel::REPL::Plugin::Colors](http://search.cpan.org/perldoc?Devel::REPL::Plugin::Colors)
123- [Devel::REPL::Plugin::Completion](http://search.cpan.org/perldoc?Devel::REPL::Plugin::Completion)
124- [Devel::REPL::Plugin::CompletionDriver::INC](http://search.cpan.org/perldoc?Devel::REPL::Plugin::CompletionDriver::INC)
125- [Devel::REPL::Plugin::CompletionDriver::LexEnv](http://search.cpan.org/perldoc?Devel::REPL::Plugin::CompletionDriver::LexEnv)
126- [Devel::REPL::Plugin::CompletionDriver::Keywords](http://search.cpan.org/perldoc?Devel::REPL::Plugin::CompletionDriver::Keywords)
127- [Devel::REPL::Plugin::CompletionDriver::Methods](http://search.cpan.org/perldoc?Devel::REPL::Plugin::CompletionDriver::Methods)
128- [Devel::REPL::Plugin::ReadlineHistory](http://search.cpan.org/perldoc?Devel::REPL::Plugin::ReadlineHistory)
129
130## Plugins
131
e962ffaa 132Plugins are a way to add functionality to the REPL shell, and take advantage of
80bc1543 133`Devel::REPL` being based on the [Moose](http://search.cpan.org/perldoc?Moose) object system for Perl 5. This
134means it's simple to 'hook into' many steps of the R-E-P-L process. Plugins
135can change the way commands are interpreted, or the way their results are
136output, or even add commands to the shell environment.
137
138A number of plugins ship with `Devel::REPL`, and more are available on the
139CPAN. Some of the shipped plugins are loaded in the default profile, mentioned
140above. These plugins can be loaded in your `$HOME/.re.pl/repl.rc` like:
141
142 load_plugin qw( CompletionDriver::Global DumpHistory );
143
144Writing your own plugins is not difficult, and is discussed in the
145[Devel::REPL::Plugin](http://search.cpan.org/perldoc?Devel::REPL::Plugin) manual page, along with links to the manual pages of
146all the plugins shipped with `Devel::REPL`.
147
148## The REPL shell object
149
150From time to time you'll want to interact with or manipulate the
151`Devel::REPL` shell object itself; that is, the instance of the shell you're
152currently running.
153
154The object is always available through the `$_REPL` variable. One common
155requirement is to load an additional plugin, after your profile and run
156control files have already been executed:
157
158 $_ $_REPL->load_plugin('Timing');
159 1
160 $_ print "Hello again, world!\n"
161 Hello again, world!
162 Took 0.00148296356201172 seconds.
163 1
164 $_
165
b76bf9f6 166# OPTIONAL FEATURES
167
168In addition to the prerequisites declared in this distribution, which should be automatically installed by your [CPAN](http://search.cpan.org/perldoc?CPAN) client, there are a number of optional features, used by
169additional plugins. You can install any of these features by installing this
170distribution interactively (e.g. `cpanm --interactive Devel::REPL`).
171
172- Completion plugin - extensible tab completion
173- DDS plugin - better format results with Data::Dump::Streamer
174- DDC plugin - even better format results with Data::Dumper::Concise
175- INC completion driver - tab complete module names in use and require
176- Interrupt plugin - traps SIGINT to kill long-running lines
177- Keywords completion driver - tab complete Perl keywords and operators
178- LexEnv plugin - variables declared with "my" persist between statements
179- MultiLine::PPI plugin - continue reading lines until all blocks are closed
180- Nopaste plugin - upload a session\\'s input and output to a Pastebin
181- PPI plugin - PPI dumping of Perl code
182- Refresh plugin - automatically reload libraries with Module::Refresh
80bc1543 183
184# AUTHOR
185
186Matt S Trout - mst (at) shadowcatsystems.co.uk ([http://www.shadowcatsystems.co.uk/](http://www.shadowcatsystems.co.uk/))
187
188# CONTRIBUTORS
189
190- Stevan Little - stevan (at) iinteractive.com
191- Alexis Sukrieh - sukria+perl (at) sukria.net
192- epitaph
193- mgrimes - mgrimes (at) cpan dot org
194- Shawn M Moore - sartak (at) gmail.com
195- Oliver Gorwits - oliver on irc.perl.org
196- Andrew Moore - `<amoore@cpan.org>`
197- Norbert Buchmuller `<norbi@nix.hu>`
198- Dave Houston `<dhouston@cpan.org>`
199- Chris Marshall
200- Karen Etheridge `<ether@cpan.org>`
201
202# LICENSE
203
204This library is free software under the same terms as perl itself