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