Skip to content

Commit

Permalink
added idle_interval attribute to Mojo::IOLoop and improved to method …
Browse files Browse the repository at this point in the history
…in Mojolicious::Routes::Route
  • Loading branch information
kraih committed Jun 20, 2012
1 parent 0474809 commit 5ed596e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -8,7 +8,10 @@
- Switched back from IO::Socket::INET6 to IO::Socket::IP for IPv6 support.
- Switched from HMAC-MD5 to HMAC-SHA1 for signed cookies.
- Added j and r functions to ojo. (sharifulin, sri)
- Added idle_interval attribute to Mojo::IOLoop.
- Added support for new HTTP status code.
- Improved to method in Mojolicious::Routes::Route to give easier access to
default parameters.
- Improved message parser performance slightly.
- Improved documentation. (ichesnokov, sri)
- Improved tests.
Expand Down
14 changes: 12 additions & 2 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -13,7 +13,8 @@ use Time::HiRes 'time';

use constant DEBUG => $ENV{MOJO_IOLOOP_DEBUG} || 0;

has client_class => 'Mojo::IOLoop::Client';
has client_class => 'Mojo::IOLoop::Client';
has idle_interval => 0.025;
has [qw(lock unlock)];
has max_accepts => 0;
has max_connections => 1000;
Expand Down Expand Up @@ -217,7 +218,7 @@ sub _listening {
sub _manage {
my $self = shift;
$self->{manager} ||= $self->recurring(
0.025 => sub {
$self->idle_interval => sub {
my $self = shift;

# Start listening if possible
Expand Down Expand Up @@ -363,6 +364,15 @@ L<Mojo::IOLoop> implements the following attributes.
Class to be used for opening TCP connections with the C<client> method,
defaults to L<Mojo::IOLoop::Client>.
=head2 C<idle_interval>
my $interval = $loop->idle_interval;
$loop = $loop->idle_interval(0.5);
Interval in seconds for checking the accept mutex and managing connections,
defaults to C<0.025>. Note that changing this value can affect performance and
idle cpu usage.
=head2 C<lock>
my $cb = $loop->lock;
Expand Down
7 changes: 6 additions & 1 deletion lib/Mojolicious/Plugin/Mount.pm
Expand Up @@ -56,7 +56,12 @@ Mojolicious::Plugin::Mount - Application mount plugin
=head1 DESCRIPTION
L<Mojolicious::Plugin::Mount> is a plugin that allows you to mount whole
L<Mojolicious> applications.
L<Mojolicious> applications. Note that secrets need to be synchronized if
sessions or signed cookies are being used.
# Synchronize secrets between applications
plugin(Mount => {'/foo' => '/home/sri/myapp.pl'})->to->{app}
->secret(app->secret);
The code of this plugin is a good example for learning to build new plugins,
you're welcome to fork it.
Expand Down
28 changes: 16 additions & 12 deletions lib/Mojolicious/Routes/Route.pm
Expand Up @@ -168,6 +168,10 @@ sub route {
sub to {
my $self = shift;

# No argument
my $pattern = $self->pattern;
return $pattern->defaults unless @_;

# Single argument
my ($shortcut, $defaults);
if (@_ == 1) {
Expand Down Expand Up @@ -210,7 +214,6 @@ sub to {
}

# Merge defaults
my $pattern = $self->pattern;
$pattern->defaults({%{$pattern->defaults}, %$defaults}) if $defaults;

return $self;
Expand Down Expand Up @@ -557,17 +560,18 @@ Generate route matching all HTTP request methods.
=head2 C<to>
$r = $r->to(action => 'foo');
$r = $r->to({action => 'foo'});
$r = $r->to('controller#action');
$r = $r->to('controller#action', foo => 'bar');
$r = $r->to('controller#action', {foo => 'bar'});
$r = $r->to($app);
$r = $r->to($app, foo => 'bar');
$r = $r->to($app, {foo => 'bar'});
$r = $r->to('MyApp');
$r = $r->to('MyApp', foo => 'bar');
$r = $r->to('MyApp', {foo => 'bar'});
my $defaults = $r->to;
$r = $r->to(action => 'foo');
$r = $r->to({action => 'foo'});
$r = $r->to('controller#action');
$r = $r->to('controller#action', foo => 'bar');
$r = $r->to('controller#action', {foo => 'bar'});
$r = $r->to($app);
$r = $r->to($app, foo => 'bar');
$r = $r->to($app, {foo => 'bar'});
$r = $r->to('MyApp');
$r = $r->to('MyApp', foo => 'bar');
$r = $r->to('MyApp', {foo => 'bar'});
Set default parameters for this route.
Expand Down
6 changes: 4 additions & 2 deletions t/mojolicious/embedded_lite_app.t
Expand Up @@ -9,7 +9,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 139;
use Test::More tests => 140;

use FindBin;
use lib "$FindBin::Bin/lib";
Expand Down Expand Up @@ -89,7 +89,9 @@ app->routes->namespace('MyTestApp');
# Mount full external application a few times
my $external = "$FindBin::Bin/external/myapp.pl";
plugin Mount => {'/x/1' => $external};
plugin(Mount => ('/x/♥' => $external))->to(message => 'works 2!');
my $route
= plugin(Mount => ('/x/♥' => $external))->to(message => 'works 2!');
is $route->to->{message}, 'works 2!', 'right message';
plugin Mount => {'/y/1' => "$FindBin::Bin/external/myapp2.pl"};
plugin Mount => {'mojolicious.org' => $external};
plugin(Mount => ('/y/♥' => "$FindBin::Bin/external/myapp2.pl"))
Expand Down
3 changes: 2 additions & 1 deletion t/mojolicious/routes.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 392;
use Test::More tests => 393;

# "They're not very heavy, but you don't hear me not complaining."
use Mojolicious::Routes;
Expand Down Expand Up @@ -209,6 +209,7 @@ is $r->find('test_edit')->to_string, '/:controller/test/edit', 'right pattern';
is $r->find('articles_delete')->to_string, '/articles/:id/delete',
'right pattern';
is $r->find('nodetect')->pattern->reqs->{format}, 0, 'right value';
is $r->find('nodetect')->to->{controller}, 'foo', 'right controller';

# Null route
$m = Mojolicious::Routes::Match->new(GET => '/0')->match($r);
Expand Down

0 comments on commit 5ed596e

Please sign in to comment.