Skip to content

Commit

Permalink
fixed small timer bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 16, 2011
1 parent ca9fcaa commit f26f3c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 3 additions & 2 deletions lib/Mojolicious/Plugin/RequestTimer.pm
Expand Up @@ -21,7 +21,8 @@ sub register {
stop_timer => sub {
my ($self, $name) = @_;
my $elapsed = sprintf '%f',
tv_interval($self->stash->{'mojo.timer'}->{$name}, [gettimeofday()]);
tv_interval($self->stash->{'mojo.timer'}->{$name} || [0, 0],
[gettimeofday()]);
return
wantarray
? ($elapsed, $elapsed == 0 ? '??' : sprintf '%.3f', 1 / $elapsed)
Expand Down Expand Up @@ -97,7 +98,7 @@ Note that this helper is EXPERIMENTAL and might change without warning!
=head2 C<stop_timer>
<%= stop_timer 'page' %>
<%= (stop_timer('page'))[1] %>
<%= my ($elapsed, $rps) = stop_timer 'page'; %>
Stop timer and return elapsed time in seconds.
Note that this helper is EXPERIMENTAL and might change without warning!
Expand Down
11 changes: 5 additions & 6 deletions t/mojolicious/tag_helper_lite_app.t
Expand Up @@ -44,11 +44,7 @@ get 'form/:test' => 'form';
put 'selection';

# GET /timed
get '/timed' => sub {
my $self = shift;
$self->start_timer('page');
$self->render(inline => '<%= stop_timer "page" %> seconds');
};
get '/timed' => sub { shift->start_timer('page') };

# GET /rps
get '/rps';
Expand Down Expand Up @@ -307,7 +303,7 @@ $t->put_ok('/selection?foo=bar&a=e&foo=baz&bar=d')->status_is(200)
. "\n");

# GET /timed
$t->get_ok('/timed')->status_is(200)->content_like(qr/\d+\.\d+\ seconds$/);
$t->get_ok('/timed')->status_is(200)->content_like(qr/\d+\.\d+\ seconds/);

# GET /rps
$t->get_ok('/rps')->status_is(200)
Expand Down Expand Up @@ -410,6 +406,9 @@ __DATA__
%= submit_button
%= end
@@ timed.html.ep
<%= stop_timer "page" %> seconds
@@ rps.html.ep
% start_timer 'foo';
lalala
Expand Down

0 comments on commit f26f3c5

Please sign in to comment.