7 Devel::REPL - A modern perl interactive shell
15 my $repl = Devel::REPL->new;
16 $repl->load_plugin($_) for qw(History LexEnv);
19 Alternatively, use the 're.pl' script installed with the distribution
25 This is an interactive shell for Perl, commonly known as a REPL - Read,
26 Evaluate, Print, Loop. The shell provides for rapid development or testing
27 of code without the need to create a temporary source code file.
29 Through a plugin system, many features are available on demand. You can also
30 tailor the environment through the use of profiles and run control files, for
31 example to pre-load certain Perl modules when working on a particular project.
35 To start a shell, follow one of the examples in the L</"SYNOPSIS"> above.
37 Once running, the shell accepts and will attempt to execute any code given. If
38 the code executes successfully you'll be shown the result, otherwise an error
39 message will be returned. Here are a few examples:
41 $_ print "Hello, world!\n"
45 Compile error: Bareword "nosuchfunction" not allowed while "strict subs" in use at (eval 130) line 5.
49 In the first example above you see the output of the command (C<Hello,
50 world!>), if any, and then the return value of the statement (C<1>). Following
51 that example, an error is returned when the execution of some code fails.
53 Note that the lack of semicolon on the end is not a mistake - the code is
54 run inside a Block structure (to protect the REPL in case the code blows up),
55 which means a single statement doesn't require the semicolon. You can add one
58 If you followed the first example in the L</"SYNOPSIS"> above, you'll have the
59 L<History|Devel::REPL::Plugin::History> and L<LexEnv|Devel::REPL::Plugin::LexEnv>
60 plugins loaded (and there are many more available).
61 Although the shell might support "up-arrow" history, the History plugin adds
62 "bang" history to that so you can re-execute chosen commands (with e.g.
63 C<!53>). The LexEnv plugin ensures that lexical variables declared with the
64 C<my> keyword will automatically persist between statements executed in the
67 When you C<use> any Perl module, the C<import()> will work as expected - the
68 exported functions from that module are available for immediate use:
70 $_ carp "I'm dieeeing!\n"
71 String found where operator expected at (eval 129) line 5, near "carp "I'm dieeeing!\n""
72 (Do you need to predeclare carp?)
73 Compile error: syntax error at (eval 129) line 5, near "carp "I'm dieeeing!\n""
74 BEGIN not safe after errors--compilation aborted at (eval 129) line 5.
78 $_ carp "I'm dieeeing!\n"
80 at /usr/share/perl5/Lexical/Persistence.pm line 327
84 To quit from the shell, hit C<Ctrl+D> or C<Ctrl+C>.
86 MSWin32 NOTE: control keys won't work if TERM=dumb
87 because readline functionality will be disabled.
89 =head2 Run Control Files
91 For particular projects you might well end up running the same commands each
92 time the REPL shell starts up - loading Perl modules, setting configuration,
93 and so on. A run control file lets you have this done automatically, and you
94 can have multiple files for different projects.
96 By default the C<re.pl> program looks for C<< $HOME/.re.pl/repl.rc >>, and
97 runs whatever code is in there as if you had entered it at the REPL shell
100 To set a new run control file that's also in that directory, pass it as a
103 system$ re.pl --rcfile myproject.pc
105 If the filename happens to contain a forward slash, then it's used absolutely,
106 or realive to the current working directory:
108 system$ re.pl --rcfile /path/to/my/project/repl.rc
110 Within the run control file you might want to load plugins. This is covered in
111 L</"The REPL shell object"> section, below.
115 To allow for the sharing of run control files, you can fashion them into a
116 Perl module for distribution (perhaps via the CPAN). For more information on
117 this feature, please see the L<Devel::REPL::Profile> manual page.
119 A C<Standard> profile ships with C<Devel::REPL>; it loads the following plugins
120 (note that some of these require optional features -- or you can also use the
127 L<Devel::REPL::Plugin::History>
131 L<Devel::REPL::Plugin::LexEnv>
135 L<Devel::REPL::Plugin::DDS>
139 L<Devel::REPL::Plugin::Packages>
143 L<Devel::REPL::Plugin::Commands>
147 L<Devel::REPL::Plugin::MultiLine::PPI>
151 L<Devel::REPL::Plugin::Colors>
155 L<Devel::REPL::Plugin::Completion>
159 L<Devel::REPL::Plugin::CompletionDriver::INC>
163 L<Devel::REPL::Plugin::CompletionDriver::LexEnv>
167 L<Devel::REPL::Plugin::CompletionDriver::Keywords>
171 L<Devel::REPL::Plugin::CompletionDriver::Methods>
175 L<Devel::REPL::Plugin::ReadlineHistory>
181 Plugins are a way to add functionality to the REPL shell, and take advantage of
182 C<Devel::REPL> being based on the L<Moose> object system for Perl 5. This
183 means it's simple to 'hook into' many steps of the R-E-P-L process. Plugins
184 can change the way commands are interpreted, or the way their results are
185 output, or even add commands to the shell environment.
187 A number of plugins ship with C<Devel::REPL>, and more are available on the
188 CPAN. Some of the shipped plugins are loaded in the default profile, mentioned
189 above. These plugins can be loaded in your F< $HOME/.re.pl/repl.rc > like:
191 load_plugin qw( CompletionDriver::Global DumpHistory );
193 Writing your own plugins is not difficult, and is discussed in the
194 L<Devel::REPL::Plugin> manual page, along with links to the manual pages of
195 all the plugins shipped with C<Devel::REPL>.
197 =head2 The REPL shell object
199 From time to time you'll want to interact with or manipulate the
200 C<Devel::REPL> shell object itself; that is, the instance of the shell you're
203 The object is always available through the C<$_REPL> variable. One common
204 requirement is to load an additional plugin, after your profile and run
205 control files have already been executed:
207 $_ $_REPL->load_plugin('Timing');
209 $_ print "Hello again, world!\n"
211 Took 0.00148296356201172 seconds.
215 =head1 OPTIONAL FEATURES
217 In addition to the prerequisites declared in this distribution, which should be automatically installed by your L<CPAN> client, there are a number of optional features, used by
218 additional plugins. You can install any of these features by installing this
219 distribution interactively (e.g. C<cpanm --interactive Devel::REPL>).
221 =for comment I hope to automatically generate this data via a Pod::Weaver section
227 Completion plugin - extensible tab completion
231 DDS plugin - better format results with Data::Dump::Streamer
235 DDC plugin - even better format results with Data::Dumper::Concise
239 INC completion driver - tab complete module names in use and require
243 Interrupt plugin - traps SIGINT to kill long-running lines
247 Keywords completion driver - tab complete Perl keywords and operators
251 LexEnv plugin - variables declared with "my" persist between statements
255 MultiLine::PPI plugin - continue reading lines until all blocks are closed
259 Nopaste plugin - upload a session\'s input and output to a Pastebin
263 PPI plugin - PPI dumping of Perl code
267 Refresh plugin - automatically reload libraries with Module::Refresh
277 L<A comparison of various REPLs|http://shadow.cat/blog/matt-s-trout/mstpan-17/>
283 Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Devel-REPL>
284 (or L<bug-Devel-REPL@rt.cpan.org|mailto:bug-Devel-REPL@rt.cpan.org>).
286 There is also an irc channel available for users of this distribution, at
287 L<C<#devel> on C<irc.perl.org>|irc://irc.perl.org/#devel-repl>.
291 Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>)
295 =for stopwords Karen Etheridge Shawn M Moore Chris Marshall Matt S Trout Oliver Gorwits יובל קוג'מן (Yuval Kogman) Arthur Axel 'fREW' Schmidt Andrew Alexis Sukrieh Tomas Doran (t0m) epitaph Norbert Buchmuller Jesse Luehrs Dave Houston Dagfinn Ilmari Mannsåker Zakariyya Mughal Ryan Niebur Justin Hunter Ash Berlin naquad Stevan Little
301 Karen Etheridge <ether@cpan.org>
305 Shawn M Moore <code@sartak.org>
309 Chris Marshall <devel.chm.01@gmail.com>
313 Matt S Trout <mst@shadowcat.co.uk>
317 Oliver Gorwits <oliver@cpan.org>
321 יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
325 Arthur Axel 'fREW' Schmidt <frioux@gmail.com>
329 Andrew Moore <amoore@cpan.org>
333 Alexis Sukrieh <sukria+perl@sukria.net>
337 Tomas Doran (t0m) <bobtfish@bobtfish.net>
345 Norbert Buchmuller <norbi@nix.hu>
349 Jesse Luehrs <doy@tozt.net>
353 Dave Houston <dhouston@cpan.org>
357 Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
361 Zakariyya Mughal <zaki.mughal@gmail.com>
365 Ryan Niebur <ryan@debian.org>
369 Justin Hunter <justin.d.hunter@gmail.com>
373 Ash Berlin <ash_github@firemirror.com>
377 naquad <naquad@bd8105ee-0ff8-0310-8827-fb3f25b6796d>
381 Stevan Little <stevan.little@iinteractive.com>
385 =head1 COPYRIGHT AND LICENCE
387 This software is copyright (c) 2007 by Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>).
389 This is free software; you can redistribute it and/or modify it under
390 the same terms as the Perl 5 programming language system itself.