3 package Devel::REPL::Plugin::FancyPrompt;
5 our $VERSION = '1.003027';
7 use Devel::REPL::Plugin;
8 use namespace::autoclean;
10 has 'fancy_prompt' => (
11 is => 'rw', lazy => 1,
13 # yes, this needs to be a double sub
17 sprintf 're.pl(%s):%03d%s> ',
18 $self->can('current_package') ? $self->current_package : 'main',
20 $self->can('line_depth') ? ':' . $self->line_depth : '';
25 has 'fancy_continuation_prompt' => (
26 is => 'rw', lazy => 1,
28 # yes, this needs to be a double sub
32 sprintf 're.pl(%s):%03d:%d* ',
33 $self->can('current_package') ? $self->current_package : 'main',
41 is => 'rw', lazy => 1, default => 0,
44 around 'prompt' => sub {
47 if ($self->can('line_depth') && $self->line_depth) {
48 return $self->fancy_continuation_prompt->($self);
51 return $self->fancy_prompt->($self);
55 before 'read' => sub {
57 $self->lines_read($self->lines_read + 1);
66 Devel::REPL::Plugin::FancyPrompt - facilitate user-defined prompts
72 my $repl = Devel::REPL->new;
73 $repl->load_plugin('MultiLine::PPI'); # for indent depth
74 $repl->load_plugin('Packages'); # for current package
75 $repl->load_plugin('FancyPrompt');
80 FancyPrompt helps you write your own prompts. The default fancy prompt resembles
81 C<irb>'s default prompt. The default C<fancy_prompt> looks like this:
83 re.pl(main):001:0> 2 + 2
86 C<re.pl> is a constant. C<main> is the current package. The first number is how
87 many lines have been read so far. The second number (only if you have a
88 C<MultiLine> plugin) is how deep you are; intuitively, your indent level. This
89 default can be implemented with:
91 $_REPL->fancy_prompt(sub {
93 sprintf 're.pl(%s):%03d%s> ',
94 $self->can('current_package') ? $self->current_package : 'main',
96 $self->can('line_depth') ? ':' . $self->line_depth : '';
99 C<current_package> is provided by L<Devel::REPL::Plugin::Packages> (which
100 tracks the current package). C<line_depth> is provided by a C<MultiLine> plugin
101 (probably C<MultiLine::PPI>).
103 You may also set a C<fancy_continuation_prompt>. The default is very similar to
104 C<fancy_prompt>'s default (except C<*> instead of C<< > >>).
112 Shawn M Moore, C<< <sartak at gmail dot com> >>
114 =head1 COPYRIGHT AND LICENSE
116 Copyright (C) 2007 by Shawn M Moore
118 This library is free software; you can redistribute it and/or modify
119 it under the same terms as Perl itself.