Add a Timing plugin to report how long each eval takes
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / Timing.pm
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;
+