fix version requirement
[p5sagit/Devel-REPL.git] / README.md
1 # NAME
2
3 Devel::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
11 Alternatively, use the 're.pl' script installed with the distribution
12
13     system$ re.pl
14
15 # DESCRIPTION
16
17 This is an interactive shell for Perl, commonly known as a REPL - Read,
18 Evaluate, Print, Loop. The shell provides for rapid development or testing
19 of code without the need to create a temporary source code file.
20
21 Through a plugin system, many features are available on demand. You can also
22 tailor the environment through the use of profiles and run control files, for
23 example to pre-load certain Perl modules when working on a particular project.
24
25 # USAGE
26
27 To start a shell, follow one of the examples in the ["SYNOPSIS"](#SYNOPSIS) above.
28
29 Once running, the shell accepts and will attempt to execute any code given. If
30 the code executes successfully you'll be shown the result, otherwise an error
31 message 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
41 In the first example above you see the output of the command (`Hello,
42 world!`), if any, and then the return value of the statement (`1`). Following
43 that example, an error is returned when the execution of some code fails.
44
45 Note that the lack of semicolon on the end is not a mistake - the code is
46 run inside a Block structure (to protect the REPL in case the code blows up),
47 which means a single statement doesn't require the semicolon. You can add one
48 if you like, though.
49
50 If you followed the first example in the ["SYNOPSIS"](#SYNOPSIS) above, you'll have the
51 History and LexEnv plugins loaded (and there are many more available).
52 Although 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
56 REPL shell.
57
58 When you `use` any Perl module, the `import()` will work as expected - the
59 exported 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
75 To 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
84 For particular projects you might well end up running the same commands each
85 time the REPL shell starts up - loading Perl modules, setting configuration,
86 and so on. A run control file lets you have this done automatically, and you
87 can have multiple files for different projects.
88
89 By default the `re.pl` program looks for `$HOME/.re.pl/repl.rc`, and
90 runs whatever code is in there as if you had entered it at the REPL shell
91 yourself.
92
93 To set a new run control file that's also in that directory, pass it as a
94 filename like so:
95
96     system$ re.pl --rcfile myproject.pc
97
98 If the filename happens to contain a forward slash, then it's used absolutely,
99 or realive to the current working directory:
100
101     system$ re.pl --rcfile /path/to/my/project/repl.rc
102
103 Within 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
108 To allow for the sharing of run control files, you can fashion them into a
109 Perl module for distribution (perhaps via the CPAN). For more information on
110 this feature, please see the [Devel::REPL::Profile](http://search.cpan.org/perldoc?Devel::REPL::Profile) manual page.
111
112 A `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):
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
132 Plugins are a way to add functionality to the REPL shell, and take advantage of
133 `Devel::REPL` being based on the [Moose](http://search.cpan.org/perldoc?Moose) object system for Perl 5. This
134 means it's simple to 'hook into' many steps of the R-E-P-L process. Plugins
135 can change the way commands are interpreted, or the way their results are
136 output, or even add commands to the shell environment.
137
138 A number of plugins ship with `Devel::REPL`, and more are available on the
139 CPAN. Some of the shipped plugins are loaded in the default profile, mentioned
140 above.  These plugins can be loaded in your `$HOME/.re.pl/repl.rc` like:
141
142     load_plugin qw( CompletionDriver::Global DumpHistory );
143
144 Writing 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
146 all the plugins shipped with `Devel::REPL`.
147
148 ## The REPL shell object
149
150 From 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
152 currently running.
153
154 The object is always available through the `$_REPL` variable. One common
155 requirement is to load an additional plugin, after your profile and run
156 control 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
166 # OPTIONAL FEATURES
167
168 In 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
169 additional plugins. You can install any of these features by installing this
170 distribution 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
183
184 # AUTHOR
185
186 Matt 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
204 This library is free software under the same terms as perl itself