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. 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
34 For Ruby it would be irb, for Python is... python byitself and for perl...
35 and there was nothing for perl (except that ugly perl -d -e "" and several
36 failed projects) until Devel::REPL was written by Matt S Trout (a.k.a. mst)
37 from ShadowCatSystems L<http://www.shadowcatsystems.co.uk>.
40 =head2 Devel::REPL - the Perl console
43 REPL stands for Read, Evaluate, Print, Loop.
44 Lets install and try it.
48 After installation you have a lot of new modules,
49 but the most interesting things are:
61 Wrapper script, running console.
65 And a bunch of plugins (I'll describe them later).
70 If everything is ok you'll see a prompt (underlined $).
71 That's it. You can start typing expressions.
79 > return $number > 1 ? $number * factorial($number-1) : $number;
83 $ factorial 1 # by the way, comments are allowed
95 3, # return values are printed with Data::Dumper::Streamer.
96 4, # See Plugins section
102 $ {apple=>1,fruit=>'apple',cart=>['apple','banana']}
112 $ package MyPackage; # create a package
114 $ sub say_hi { # define a sub
118 > } # statement is evaluated only after we've finished typing block.
119 # See Plugins section.
132 =head2 Control files a.k.a. I don't want to type it every time
134 Devel::REPL has control files feature. Control files are
135 evaluated on session start in the same way as you would
136 type them manually in console.
138 Default control file is located at `$HOME/.re.pl/repl.rc` .
140 You can store there any statements you would normally type in.
142 I.e. my `$HOME/.re.pl/repl.rc` has next lines:
144 use feature 'say'; # to don't write \n all the time
148 # pretty print data structures
149 sub pp { print Data::Dumper->Dump([@_]) }
151 You can have multiple control files and they can be anywhere in the
152 file system. To make re.pl use some rc-file other than repl.rc
155 $ re.pl --rcfile /path/to/your/rc.file
157 If your rc-file is in `$HOME/.re.pl` directory, you can omit path:
159 $ re.pl --rcfile rc.file
161 If you have rc-file with the same name in current directory
162 and you don't want to type path, you can:
164 $ re.pl --rcfile ./rc.file
166 =head2 I want it to bark, fly, jump and swim! or Plugins
168 Plugins extend functionality and change behavor of Devel::REPL.
175 Devel::REPL::Plugin::History
176 No comments. Simply history.
180 Devel::REPL::Plugin::!LexEnv
181 Provides a lexical environment for the Devel::REPL.
185 Devel::REPL::Plugin::DDS
186 Formats return values with Data::Dump::Streamer module.
190 Devel::REPL::Plugin::Packages
191 Keeps track of which package your're in.
195 Devel::REPL::Plugin::Commands
196 Generic command creation plugin using injected functions.
200 Devel::REPL::Plugin::MultiLine::PPI
201 Makes Devel::REPL read your input until your block
202 is finished. What does this means: you can type a part of a block
203 on one line and second part on another:
207 > print "Hello, World!\n"; ## notice prompt change
216 but this *doesn't* mean you can print sub name or identifier
217 on several lines. Don't do that! It won't work.
222 There are lots of contributed plugins you can find at CPAN.
226 If plugins change and extend functionality of Devel::REPL, profiles
227 are changing your environment (loaded plugins, constants, subs and etc.).
229 There's only one bundled profile called `Devel::REPL::Profile::Default`, lets
232 package Devel::REPL::Profile::Default;
234 use Moose; ### advanced OOP system for Perl
236 ### keep those exports/imports out of our namespace
237 use namespace::clean -except => [ 'meta' ];
239 with 'Devel::REPL::Profile'; ## seem perldoc Muse
241 sub plugins { ### plugins we want to be loaded
242 qw(History LexEnv DDS Packages Commands MultiLine::PPI);
245 ### the only required sub for profile,
246 ### it is called on profile activation
248 my ($self, $repl) = @_;
249 ### $self - no comments, $repl - current instance of Devel::REPL
251 $repl->load_plugin($_) for $self->plugins; ### load our plugins
256 At the moment there are no profiles on CPAN. Mostly you'll use control files.
257 To enable some profile use --profile switch:
259 $ re.pl --profile SomeProfile
263 L<Devel::REPL>, L<Devel::REPL::Plugin>, L<Devel::REPL::Profile>