From: Sartak Date: Sat, 3 Nov 2007 00:23:56 +0000 (+0000) Subject: Add a Timing plugin to report how long each eval takes X-Git-Tag: v1.003015~142 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=296c23ff27911024929500d8b6f04cec5d711da4;p=p5sagit%2FDevel-REPL.git Add a Timing plugin to report how long each eval takes This is probably going to be better served as a command itself git-svn-id: http://dev.catalyst.perl.org/repos/bast/trunk/Devel-REPL@3851 bd8105ee-0ff8-0310-8827-fb3f25b6796d --- diff --git a/lib/Devel/REPL/Plugin/Timing.pm b/lib/Devel/REPL/Plugin/Timing.pm new file mode 100644 index 0000000..13f47d0 --- /dev/null +++ b/lib/Devel/REPL/Plugin/Timing.pm @@ -0,0 +1,26 @@ +package Devel::REPL::Plugin::Timing; + +use Moose::Role; +use Time::HiRes 'time'; +use namespace::clean -except => [ 'meta' ]; + +around 'eval' => sub { + my $orig = shift; + my ($self, $line) = @_; + + my @ret; + my $start = time; + + if (wantarray) { + @ret = $self->$orig($line); + } + else { + $ret[0] = $self->$orig($line); + } + + $self->print("Took " . (time - $start) . " seconds.\n"); + return @ret; +}; + +1; +