3 Devel::REPL::Overview - overview of Devel::REPL.
7 =head2 What is a console? How it can assist you?
9 Most modern languages have consoles. The console is an interactive tool
10 that evaluates your input while you type it.
11 It gives you several advantages:
17 Quickly test some thought or tricky expression
21 Run some code bigger than one line without a temporary file
25 Play around with libraries and modules
29 You can even call a console in your script and play around in script's context
33 For Ruby it would be irb, for Python is... python by itself and for perl...
34 and there was nothing for perl (except that ugly perl -d -e "" and several
35 failed projects) until L<Devel::REPL> was written by Matt S Trout (a.k.a. mst)
36 from ShadowCatSystems L<http://www.shadowcatsystems.co.uk>.
38 =head2 Devel::REPL - the Perl console
40 REPL stands for Read, Evaluate, Print, Loop.
41 Lets install and try it.
45 After installation you have a lot of new modules,
46 but the most interesting things are:
58 Wrapper script, running console.
62 And a bunch of plugins (I'll describe them later).
67 If everything is ok you'll see a prompt (underlined $).
68 That's it. You can start typing expressions.
76 > return $number > 1 ? $number * factorial($number-1) : $number;
80 $ factorial 1 # by the way, comments are allowed
92 3, # return values are printed with Data::Dumper::Streamer.
93 4, # See Plugins section
99 $ {apple=>1,fruit=>'apple',cart=>['apple','banana']}
109 $ package MyPackage; # create a package
111 $ sub say_hi { # define a sub
115 > } # statement is evaluated only after we've finished typing block.
116 # See Plugins section.
129 =head2 Control files a.k.a. I don't want to type it every time
131 L<Devel::REPL> has a control files feature. Control files are
132 evaluated on session start in the same way as you would
133 type them manually in the console.
135 The default control file is located at F<$HOME/.re.pl/repl.rc>.
137 You can store there any statements you would normally type in.
139 I.e. my F<$HOME/.re.pl/repl.rc> has next lines:
141 use feature 'say'; # to don't write \n all the time
145 # pretty print data structures
146 sub pp { print Data::Dumper->Dump([@_]) }
148 You can have multiple control files and they can be anywhere in the
149 file system. To make F<re.pl> use some rc-file other than F<repl.rc>,
152 $ re.pl --rcfile /path/to/your/rc.file
154 If your rc-file is in F<$HOME/.re.pl> directory, you can omit the path:
156 $ re.pl --rcfile rc.file
158 If you have rc-file with the same name in current directory
159 and you don't want to type path, you can:
161 $ re.pl --rcfile ./rc.file
163 =head2 I want it to bark, fly, jump and swim! or Plugins
165 Plugins extend functionality and change behavior of Devel::REPL.
172 L<Devel::REPL::Plugin::History>
173 No comments. Simply history.
177 L<Devel::REPL::Plugin::!LexEnv>
178 Provides a lexical environment for the Devel::REPL.
182 L<Devel::REPL::Plugin::DDS>
183 Formats return values with Data::Dump::Streamer module.
187 L<Devel::REPL::Plugin::Packages>
188 Keeps track of which package your're in.
192 L<Devel::REPL::Plugin::Commands>
193 Generic command creation plugin using injected functions.
197 L<Devel::REPL::Plugin::MultiLine::PPI>
198 Makes Devel::REPL read your input until your block
199 is finished. What does this means: you can type a part of a block
200 on one line and second part on another:
204 > print "Hello, World!\n"; ## notice prompt change
213 but this *doesn't* mean you can print sub name or identifier
214 on several lines. Don't do that! It won't work.
218 There are lots of contributed plugins you can find at CPAN.
222 If plugins change and extend functionality of L<Devel::REPL>, profiles
223 are changing your environment (loaded plugins, constants, subs and etc.).
225 For example, the Minimal profile, L<Devel::REPL::Profile::Minimal>:
227 package Devel::REPL::Profile::Minimal;
229 use Moose; ### advanced OOP system for Perl
231 ### keep those exports/imports out of our namespace
232 use namespace::autoclean;
234 with 'Devel::REPL::Profile'; ## seem perldoc Muse
236 sub plugins { ### plugins we want to be loaded
237 qw(History LexEnv DDS Packages Commands MultiLine::PPI);
240 ### the only required sub for profile,
241 ### it is called on profile activation
243 my ($self, $repl) = @_;
244 ### $self - no comments, $repl - current instance of Devel::REPL
246 $repl->load_plugin($_) for $self->plugins; ### load our plugins
251 There is also the L<StandardDevel::REPL::Profile::Standard> profile, which contains a number of optional (yet
252 very useful) features.
254 To enable some profile use the C<--profile> switch:
256 $ re.pl --profile SomeProfile
258 Alternatively, you can set the environment variable C<DEVEL_REPL_PROFILE> to
259 C<SomeProfile>, or set the C<profile> key in your C<rcfile> (see
260 L<Devel::REPL> for more information).
272 L<Devel::REPL::Plugin>
276 L<Devel::REPL::Profile>