diff options
Diffstat (limited to 'lib/Reply/Plugin/Timer.pm')
-rw-r--r-- | lib/Reply/Plugin/Timer.pm | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/lib/Reply/Plugin/Timer.pm b/lib/Reply/Plugin/Timer.pm index a3ec247..bef91d7 100644 --- a/lib/Reply/Plugin/Timer.pm +++ b/lib/Reply/Plugin/Timer.pm @@ -1,9 +1,9 @@ -package Reply::Plugin::Timer; +package main; use strict; use warnings; # ABSTRACT: time commands -use base 'Reply::Plugin'; +use mop; use Time::HiRes qw(gettimeofday tv_interval); @@ -20,33 +20,24 @@ the default C<mintime> is C<< 0.01 >> seconds. =cut -sub new { - my $class = shift; - my %opts = @_; +class Reply::Plugin::Timer extends Reply::Plugin { + has $mintime = 0.01; - my $self = $class->SUPER::new(@_); - $self->{mintime} = $opts{mintime} || 0.01; + method execute ($next, @args) { + my $t0 = [gettimeofday]; + my $ret = $next->(@args); + my $elapsed = tv_interval($t0); - return $self; -} - - -sub execute { - my ($self, $next, @args) = @_; - - my $t0 = [gettimeofday]; - my $ret = $next->(@args); - my $elapsed = tv_interval($t0); - - if ($elapsed > $self->{mintime}) { - if ($elapsed >= 1) { - printf "Execution Time: %0.3fs\n", $elapsed - } else { - printf "Execution Time: %dms\n", $elapsed * 1000 + if ($elapsed > $mintime) { + if ($elapsed >= 1) { + printf "Execution Time: %0.3fs\n", $elapsed + } else { + printf "Execution Time: %dms\n", $elapsed * 1000 + } } - } - return $ret; + return $ret; + } } 1; |