Devel-REPL-1.003021
[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 forwardslash, 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 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
130 Plugins are a way to add funcionality to the REPL shell, and take advantage of
131 `Devel::REPL` being based on the [Moose](http://search.cpan.org/perldoc?Moose) object system for Perl 5. This
132 means it's simple to 'hook into' many steps of the R-E-P-L process. Plugins
133 can change the way commands are interpreted, or the way their results are
134 output, or even add commands to the shell environment.
135
136 A number of plugins ship with `Devel::REPL`, and more are available on the
137 CPAN. Some of the shipped plugins are loaded in the default profile, mentioned
138 above.  These plugins can be loaded in your `$HOME/.re.pl/repl.rc` like:
139
140     load_plugin qw( CompletionDriver::Global DumpHistory );
141
142 Writing 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
144 all the plugins shipped with `Devel::REPL`.
145
146 ## The REPL shell object
147
148 From 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
150 currently running.
151
152 The object is always available through the `$_REPL` variable. One common
153 requirement is to load an additional plugin, after your profile and run
154 control 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
166 In addition to the contents of the standard Perl distribution, you will need
167 the 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
179 Optionally, 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
193 Matt 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
211 This library is free software under the same terms as perl itself