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