Add a Timing plugin to report how long each eval takes
Sartak [Sat, 3 Nov 2007 00:23:56 +0000 (00:23 +0000)]
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

lib/Devel/REPL/Plugin/Timing.pm [new file with mode: 0644]

diff --git a/lib/Devel/REPL/Plugin/Timing.pm b/lib/Devel/REPL/Plugin/Timing.pm
new file mode 100644 (file)
index 0000000..13f47d0
--- /dev/null
@@ -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;
+