5 Devel::REPL::Overview - overview of Devel::REPL.
9 =head2 What is a console? How it can assist you?
11 Most modern languages have consoles. The console is an interactive tool
12 that evaluates your input while you type it.
13 It gives you several advantages:
19 Quickly test some thought or tricky expression
23 Run some code bigger than one line without a temporary file
27 Play around with libraries and modules
31 You can even call a console in your script and play around in script's context
35 For Ruby it would be irb, for Python is... python by itself and for perl...
36 and there was nothing for perl (except that ugly perl -d -e "" and several
37 failed projects) until L<Devel::REPL> was written by Matt S Trout (a.k.a. mst)
38 from ShadowCatSystems L<http://www.shadowcatsystems.co.uk>.
40 =head2 Devel::REPL - the Perl console
42 REPL stands for Read, Evaluate, Print, Loop.
43 Lets install and try it.
47 After installation you have a lot of new modules,
48 but the most interesting things are:
60 Wrapper script, running console.
64 And a bunch of plugins (I'll describe them later).
69 If everything is ok you'll see a prompt (underlined $).
70 That's it. You can start typing expressions.
78 > return $number > 1 ? $number * factorial($number-1) : $number;
82 $ factorial 1 # by the way, comments are allowed
94 3, # return values are printed with Data::Dumper::Streamer.
95 4, # See Plugins section
101 $ {apple=>1,fruit=>'apple',cart=>['apple','banana']}
111 $ package MyPackage; # create a package
113 $ sub say_hi { # define a sub
117 > } # statement is evaluated only after we've finished typing block.
118 # See Plugins section.
131 =head2 Control files a.k.a. I don't want to type it every time
133 L<Devel::REPL> has a control files feature. Control files are
134 evaluated on session start in the same way as you would
135 type them manually in the console.
137 The default control file is located at F<$HOME/.re.pl/repl.rc>.
139 You can store there any statements you would normally type in.
141 I.e. my F<$HOME/.re.pl/repl.rc> has next lines:
143 use feature 'say'; # to don't write \n all the time
147 # pretty print data structures
148 sub pp { print Data::Dumper->Dump([@_]) }
150 You can have multiple control files and they can be anywhere in the
151 file system. To make F<re.pl> use some rc-file other than F<repl.rc>,
154 $ re.pl --rcfile /path/to/your/rc.file
156 If your rc-file is in F<$HOME/.re.pl> directory, you can omit the path:
158 $ re.pl --rcfile rc.file
160 If you have rc-file with the same name in current directory
161 and you don't want to type path, you can:
163 $ re.pl --rcfile ./rc.file
165 =head2 I want it to bark, fly, jump and swim! or Plugins
167 Plugins extend functionality and change behavior of Devel::REPL.
174 L<Devel::REPL::Plugin::History>
175 No comments. Simply history.
179 L<Devel::REPL::Plugin::!LexEnv>
180 Provides a lexical environment for the Devel::REPL.
184 L<Devel::REPL::Plugin::DDS>
185 Formats return values with Data::Dump::Streamer module.
189 L<Devel::REPL::Plugin::Packages>
190 Keeps track of which package your're in.
194 L<Devel::REPL::Plugin::Commands>
195 Generic command creation plugin using injected functions.
199 L<Devel::REPL::Plugin::MultiLine::PPI>
200 Makes Devel::REPL read your input until your block
201 is finished. What does this means: you can type a part of a block
202 on one line and second part on another:
206 > print "Hello, World!\n"; ## notice prompt change
215 but this *doesn't* mean you can print sub name or identifier
216 on several lines. Don't do that! It won't work.
220 There are lots of contributed plugins you can find at CPAN.
224 If plugins change and extend functionality of L<Devel::REPL>, profiles
225 are changing your environment (loaded plugins, constants, subs and etc.).
227 For example, the Minimal profile, L<Devel::REPL::Profile::Minimal>:
229 package Devel::REPL::Profile::Minimal;
231 use Moose; ### advanced OOP system for Perl
233 ### keep those exports/imports out of our namespace
234 use namespace::autoclean;
236 with 'Devel::REPL::Profile'; ## seem perldoc Muse
238 sub plugins { ### plugins we want to be loaded
239 qw(History LexEnv DDS Packages Commands MultiLine::PPI);
242 ### the only required sub for profile,
243 ### it is called on profile activation
245 my ($self, $repl) = @_;
246 ### $self - no comments, $repl - current instance of Devel::REPL
248 $repl->load_plugin($_) for $self->plugins; ### load our plugins
253 There is also the L<StandardDevel::REPL::Profile::Standard> profile, which contains a number of optional (yet
254 very useful) features.
256 To enable some profile use the C<--profile> switch:
258 $ re.pl --profile SomeProfile
260 Alternatively, you can set the environment variable C<DEVEL_REPL_PROFILE> to
261 C<SomeProfile>, or set the C<profile> key in your C<rcfile> (see
262 L<Devel::REPL> for more information).
268 * L<Devel::REPL::Plugin>
269 * L<Devel::REPL::Profile>