increment $VERSION after 1.003029 release
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / FancyPrompt.pm
CommitLineData
1716b200 1use strict;
2use warnings;
b21e7551 3package Devel::REPL::Plugin::FancyPrompt;
9d2a4940 4# ABSTRACT: Facilitate user-defined prompts
b21e7551 5
77327851 6our $VERSION = '1.003030';
54beb05d 7
6a5409bc 8use Devel::REPL::Plugin;
aa8b7647 9use namespace::autoclean;
b21e7551 10
11has 'fancy_prompt' => (
12 is => 'rw', lazy => 1,
13
14 # yes, this needs to be a double sub
15 default => sub {
16 sub {
17 my $self = shift;
18 sprintf 're.pl(%s):%03d%s> ',
19 $self->can('current_package') ? $self->current_package : 'main',
20 $self->lines_read,
21 $self->can('line_depth') ? ':' . $self->line_depth : '';
22 }
23 },
24);
25
26has 'fancy_continuation_prompt' => (
27 is => 'rw', lazy => 1,
28
29 # yes, this needs to be a double sub
30 default => sub {
31 sub {
32 my $self = shift;
33 sprintf 're.pl(%s):%03d:%d* ',
34 $self->can('current_package') ? $self->current_package : 'main',
35 $self->lines_read,
36 $self->line_depth,
37 }
38 },
39);
40
41has 'lines_read' => (
42 is => 'rw', lazy => 1, default => 0,
43);
44
45around 'prompt' => sub {
46 shift;
47 my $self = shift;
48 if ($self->can('line_depth') && $self->line_depth) {
49 return $self->fancy_continuation_prompt->($self);
50 }
51 else {
52 return $self->fancy_prompt->($self);
53 }
54};
55
56before 'read' => sub {
57 my $self = shift;
58 $self->lines_read($self->lines_read + 1);
59};
60
611;
62
63__END__
64
9d2a4940 65=pod
b21e7551 66
67=head1 SYNOPSIS
68
b21e7551 69 use Devel::REPL;
70
71 my $repl = Devel::REPL->new;
72 $repl->load_plugin('MultiLine::PPI'); # for indent depth
73 $repl->load_plugin('Packages'); # for current package
74 $repl->load_plugin('FancyPrompt');
75 $repl->run;
76
77=head1 DESCRIPTION
78
79FancyPrompt helps you write your own prompts. The default fancy prompt resembles
80C<irb>'s default prompt. The default C<fancy_prompt> looks like this:
81
82 re.pl(main):001:0> 2 + 2
83 4
84
85C<re.pl> is a constant. C<main> is the current package. The first number is how
86many lines have been read so far. The second number (only if you have a
87C<MultiLine> plugin) is how deep you are; intuitively, your indent level. This
88default can be implemented with:
89
90 $_REPL->fancy_prompt(sub {
91 my $self = shift;
92 sprintf 're.pl(%s):%03d%s> ',
93 $self->can('current_package') ? $self->current_package : 'main',
94 $self->lines_read,
95 $self->can('line_depth') ? ':' . $self->line_depth : '';
96 });
97
98C<current_package> is provided by L<Devel::REPL::Plugin::Packages> (which
99tracks the current package). C<line_depth> is provided by a C<MultiLine> plugin
100(probably C<MultiLine::PPI>).
101
102You may also set a C<fancy_continuation_prompt>. The default is very similar to
103C<fancy_prompt>'s default (except C<*> instead of C<< > >>).
104
105=head1 SEE ALSO
106
107C<Devel::REPL>
108
109=head1 AUTHOR
110
111Shawn M Moore, C<< <sartak at gmail dot com> >>
112
113=head1 COPYRIGHT AND LICENSE
114
115Copyright (C) 2007 by Shawn M Moore
116
117This library is free software; you can redistribute it and/or modify
118it under the same terms as Perl itself.
119
120=cut