Fixed History to work with ReadLineHistory
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / Timing.pm
1 package Devel::REPL::Plugin::Timing;
2
3 use Devel::REPL::Plugin;
4 use Time::HiRes 'time';
5 use namespace::clean -except => [ 'meta' ];
6
7 around 'eval' => sub {
8     my $orig = shift;
9     my ($self, $line) = @_;
10
11     my @ret;
12     my $start = time;
13
14     if (wantarray) {
15         @ret = $self->$orig($line);
16     }
17     else {
18         $ret[0] = $self->$orig($line);
19     }
20
21     $self->print("Took " . (time - $start) . " seconds.\n");
22     return @ret;
23 };
24
25 1;
26
27 __END__
28
29 =head1 NAME
30
31 Devel::REPL::Plugin::Timing - display execution times
32
33 =head1 SYNOPSIS
34
35  # in your re.pl file:
36  use Devel::REPL;
37  my $repl = Devel::REPL->new;
38  $repl->load_plugin('Timing');
39
40  # after you run re.pl:
41  $ sum map $_*100, 1..100000;
42  Took 0.0830280780792236 seconds.
43  500005000000
44
45  $
46
47 =head1 AUTHOR
48
49 Shawn M Moore, C<< <sartak at gmail dot com> >>
50
51 =cut
52