Skip to content

Commit

Permalink
Merged in master
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusramberg committed Feb 21, 2012
2 parents e1889c6 + ef0378f commit 1cb4e0b
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 56 deletions.
8 changes: 7 additions & 1 deletion Changes
@@ -1,6 +1,12 @@
This file documents the revision history for Perl extension Mojolicious.

2.52 2012-00-00 00:00:00

2.52 2012-02-20 00:00:00
- Removed experimental status from config method in Mojo.
- Renamed to_psgi method in Mojo::Server::PSGI to to_psgi_app.
- Improved documentation.
- Fixed bug that prevented Mojo::IOLoop from dying when started
twice.
- Fixed a cookie jar path parsing bug.

2.51 2012-02-19 00:00:00
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo.pm
Expand Up @@ -156,8 +156,7 @@ object.
$app = $app->config({foo => 'bar'});
$app = $app->config(foo => 'bar');
Application configuration. Note that this method is EXPERIMENTAL and might
change without warning!
Application configuration.
$app->config->{foo} = 'bar';
my $foo = $app->config->{foo};
Expand Down
5 changes: 2 additions & 3 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -166,15 +166,14 @@ sub singleton { state $loop ||= shift->SUPER::new }
sub start {
my $self = shift;
$self = $self->singleton unless ref $self;
croak 'Mojo::IOLoop already running' if $self->{running}++;
croak 'Mojo::IOLoop already running' if $self->is_running;
$self->iowatcher->start;
return $self;
}

sub stop {
my $self = shift;
$self = $self->singleton unless ref $self;
$self->iowatcher->stop if delete $self->{running};
(ref $self ? $self : $self->singleton)->iowatcher->stop;
}

sub stream {
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/IOWatcher.pm
Expand Up @@ -225,7 +225,8 @@ amount of seconds.
$watcher->start;
Start watching for I/O and timer events.
Start watching for I/O and timer events, this will block until C<stop> is
called.
=head2 C<stop>
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/IOWatcher/EV.pm
Expand Up @@ -122,7 +122,8 @@ amount of seconds.
$watcher->start;
Start watching for I/O and timer events.
Start watching for I/O and timer events, this will block until C<stop> is
called.
=head2 C<stop>
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/Server/PSGI.pm
Expand Up @@ -49,7 +49,7 @@ sub run {
\@headers, Mojo::Server::PSGI::_IO->new(tx => $tx)];
}

sub to_psgi {
sub to_psgi_app {
(my $self = shift)->app;
return sub { $self->run(@_) }
}
Expand Down Expand Up @@ -110,7 +110,7 @@ Mojo::Server::PSGI - PSGI server
# Resume transaction
$tx->resume;
});
my $app = $psgi->to_psgi;
my $app = $psgi->to_psgi_app;
=head1 DESCRIPTION
Expand All @@ -134,9 +134,9 @@ implements the following new ones.
Run L<PSGI>.
=head2 C<to_psgi>
=head2 C<to_psgi_app>
my $app = $psgi->to_psgi;
my $app = $psgi->to_psgi_app;
Turn L<Mojo> application into L<PSGI> application. Note that this method is
EXPERIMENTAL and might change without warning!
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious.pm
Expand Up @@ -32,7 +32,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Leaf Fluttering In Wind';
our $VERSION = '2.51';
our $VERSION = '2.52';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down Expand Up @@ -681,7 +681,7 @@ that have been used in the past.
0.999920, C<Snowman> (u2603)
=head1 AUTHOR
=head1 PROJECT FOUNDER
Sebastian Riedel, C<sri@cpan.org>
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Command/psgi.pm
Expand Up @@ -8,7 +8,7 @@ has usage => "usage: $0 psgi\n";

# "In the end it was not guns or bombs that defeated the aliens,
# but that humblest of all God's creatures... the Tyrannosaurus Rex."
sub run { Mojo::Server::PSGI->new->to_psgi }
sub run { Mojo::Server::PSGI->new->to_psgi_app }

1;
__END__
Expand Down
72 changes: 36 additions & 36 deletions t/mojo/ioloop_tls.t
Expand Up @@ -66,7 +66,7 @@ is $client, 'test321', 'right content';
$loop = Mojo::IOLoop->singleton;
$port = Mojo::IOLoop->generate_port;
$server = $client = '';
my ($drop, $running, $timeout, $server_error, $server_close, $client_close);
my ($drop, $running, $timeout, $server_err, $server_close, $client_close);
Mojo::IOLoop->drop(Mojo::IOLoop->recurring(0 => sub { $drop++ }));
$loop->server(
port => $port,
Expand All @@ -80,7 +80,7 @@ $loop->server(
$running = Mojo::IOLoop->is_running;
$stream->on(timeout => sub { $timeout++ });
$stream->on(close => sub { $server_close++ });
$stream->on(error => sub { $server_error = pop });
$stream->on(error => sub { $server_err = pop });
$stream->on(read => sub { $server .= pop });
$stream->timeout('0.5');
}
Expand All @@ -105,60 +105,60 @@ is $timeout, 1, 'server emitted timeout event once';
is $server_close, 1, 'server emitted close event once';
is $client_close, 1, 'client emitted close event once';
ok $running, 'loop was running';
ok !$drop, 'event dropped successfully';
ok !$server_error, 'no error';
ok !$drop, 'event dropped successfully';
ok !$server_err, 'no error';

# Invalid client certificate
my $client_error;
my $client_err;
$loop->client(
port => $port,
tls => 1,
tls_cert => 't/mojo/certs/badclient.crt',
tls_key => 't/mojo/certs/badclient.key',
sub { shift; $client_error = shift }
sub { shift; $client_err = shift }
);
$loop->timer(1 => sub { shift->stop });
$loop->start;
ok $client_error, 'has error';
ok $client_err, 'has error';

# Missing client certificate
$server_error = $client_error = '';
$loop->client(
{port => $port, tls => 1} => sub { shift; $client_error = shift });
$server_err = $client_err = '';
$loop->client({port => $port, tls => 1} => sub { shift; $client_err = shift }
);
$loop->timer(1 => sub { shift->stop });
$loop->start;
ok !$server_error, 'no error';
ok $client_error, 'has error';
ok !$server_err, 'no error';
ok $client_err, 'has error';

# Invalid certificate authority (server)
$loop = Mojo::IOLoop->new;
$port = Mojo::IOLoop->generate_port;
$server_error = $client_error = '';
$loop = Mojo::IOLoop->new;
$port = Mojo::IOLoop->generate_port;
$server_err = $client_err = '';
$loop->server(
port => $port,
tls => 1,
tls_ca => 'no cert',
tls_cert => 't/mojo/certs/server.crt',
tls_key => 't/mojo/certs/server.key',
sub { $server_error = 'connected!' }
sub { $server_err = 'connected!' }
);
$loop->client(
port => $port,
tls => 1,
tls_cert => 't/mojo/certs/client.crt',
tls_key => 't/mojo/certs/client.key',
sub { shift; $client_error = shift }
sub { shift; $client_err = shift }
);
$loop->timer(1 => sub { shift->stop });
$loop->start;
ok !$server_error, 'no error';
ok $client_error, 'has error';
ok !$server_err, 'no error';
ok $client_err, 'has error';

# Valid client and server certificates
$loop = Mojo::IOLoop->singleton;
$port = Mojo::IOLoop->generate_port;
$server = $client = '';
($running, $timeout, $server_error, $server_close, $client_close) = undef;
($running, $timeout, $server_err, $server_close, $client_close) = undef;
$loop->server(
port => $port,
tls => 1,
Expand All @@ -171,7 +171,7 @@ $loop->server(
$running = Mojo::IOLoop->is_running;
$stream->on(timeout => sub { $timeout++ });
$stream->on(close => sub { $server_close++ });
$stream->on(error => sub { $server_error = pop });
$stream->on(error => sub { $server_err = pop });
$stream->on(read => sub { $server .= pop });
$stream->timeout('0.5');
}
Expand All @@ -197,48 +197,48 @@ is $timeout, 1, 'server emitted timeout event once';
is $server_close, 1, 'server emitted close event once';
is $client_close, 1, 'client emitted close event once';
ok $running, 'loop was running';
ok !$server_error, 'no error';
ok !$server_err, 'no error';

# Invalid server certificate
$loop = Mojo::IOLoop->new;
$port = Mojo::IOLoop->generate_port;
$server_error = $client_error = '';
$loop = Mojo::IOLoop->new;
$port = Mojo::IOLoop->generate_port;
$server_err = $client_err = '';
$loop->server(
port => $port,
tls => 1,
tls_cert => 't/mojo/certs/badclient.crt',
tls_key => 't/mojo/certs/badclient.key',
sub { $server_error = 'connected!' }
sub { $server_err = 'connected!' }
);
$loop->client(
port => $port,
tls => 1,
tls_ca => 't/mojo/certs/ca.crt',
sub { shift; $client_error = shift }
sub { shift; $client_err = shift }
);
$loop->timer(1 => sub { shift->stop });
$loop->start;
ok !$server_error, 'no error';
ok $client_error, 'has error';
ok !$server_err, 'no error';
ok $client_err, 'has error';

# Invalid certificate authority (client)
$loop = Mojo::IOLoop->new;
$port = Mojo::IOLoop->generate_port;
$server_error = $client_error = '';
$loop = Mojo::IOLoop->new;
$port = Mojo::IOLoop->generate_port;
$server_err = $client_err = '';
$loop->server(
port => $port,
tls => 1,
tls_cert => 't/mojo/certs/badclient.crt',
tls_key => 't/mojo/certs/badclient.key',
sub { $server_error = 'connected!' }
sub { $server_err = 'connected!' }
);
$loop->client(
port => $port,
tls => 1,
tls_ca => 'no cert',
sub { shift; $client_error = shift }
sub { shift; $client_err = shift }
);
$loop->timer(1 => sub { shift->stop });
$loop->start;
ok !$server_error, 'no error';
ok $client_error, 'has error';
ok !$server_err, 'no error';
ok $client_err, 'has error';
10 changes: 8 additions & 2 deletions t/mojo/iowatcher.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher';
}

use Test::More tests => 64;
use Test::More tests => 66;

# "I don't mind being called a liar when I'm lying, or about to lie,
# or just finished lying, but NOT WHEN I'M TELLING THE TRUTH."
Expand Down Expand Up @@ -190,14 +190,16 @@ $ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher';
is ref Mojo::IOLoop->singleton->iowatcher, 'Mojo::IOWatcher', 'right object';
ok !Mojo::IOLoop->is_running, 'loop is not running';
$port = Mojo::IOLoop->generate_port;
my ($server_running, $client_running);
my ($server_err, $server_running, $client_err, $client_running);
($server, $client) = '';
Mojo::IOLoop->server(
{port => $port} => sub {
my ($loop, $stream) = @_;
$stream->write('test', sub { shift->write('321') });
$stream->on(read => sub { $server .= pop });
$server_running = Mojo::IOLoop->is_running;
eval { Mojo::IOLoop->start };
$server_err = $@;
}
);
Mojo::IOLoop->client(
Expand All @@ -206,11 +208,15 @@ Mojo::IOLoop->client(
$stream->write('tset', sub { shift->write('123') });
$stream->on(read => sub { $client .= pop });
$client_running = Mojo::IOLoop->is_running;
eval { Mojo::IOLoop->start };
$client_err = $@;
}
);
Mojo::IOLoop->timer(1 => sub { Mojo::IOLoop->singleton->iowatcher->stop });
Mojo::IOLoop->singleton->iowatcher->start;
ok !Mojo::IOLoop->is_running, 'loop is not running';
like $server_err, qr/^Mojo::IOLoop already running/, 'right error';
like $client_err, qr/^Mojo::IOLoop already running/, 'right error';
ok $server_running, 'loop is running';
ok $client_running, 'loop is running';
is $server, 'tset123', 'right content';
Expand Down
10 changes: 8 additions & 2 deletions t/mojo/iowatcher_ev.t
Expand Up @@ -8,7 +8,7 @@ use Test::More;
plan skip_all => 'set TEST_EV to enable this test (developer only!)'
unless $ENV{TEST_EV};
plan skip_all => 'EV 4.0 required for this test!' unless eval 'use EV 4.0; 1';
plan tests => 64;
plan tests => 66;

use IO::Socket::INET;

Expand Down Expand Up @@ -192,14 +192,16 @@ is ref Mojo::IOLoop->singleton->iowatcher, 'Mojo::IOWatcher::EV',
'right object';
ok !Mojo::IOLoop->is_running, 'loop is not running';
$port = Mojo::IOLoop->generate_port;
my ($server_running, $client_running);
my ($server_err, $server_running, $client_err, $client_running);
($server, $client) = '';
Mojo::IOLoop->server(
{port => $port} => sub {
my ($loop, $stream) = @_;
$stream->write('test', sub { shift->write('321') });
$stream->on(read => sub { $server .= pop });
$server_running = Mojo::IOLoop->is_running;
eval { Mojo::IOLoop->start };
$server_err = $@;
}
);
Mojo::IOLoop->client(
Expand All @@ -208,11 +210,15 @@ Mojo::IOLoop->client(
$stream->write('tset', sub { shift->write('123') });
$stream->on(read => sub { $client .= pop });
$client_running = Mojo::IOLoop->is_running;
eval { Mojo::IOLoop->start };
$client_err = $@;
}
);
Mojo::IOLoop->timer(1 => sub { EV::break(EV::BREAK_ONE()) });
EV::run();
ok !Mojo::IOLoop->is_running, 'loop is not running';
like $server_err, qr/^Mojo::IOLoop already running/, 'right error';
like $client_err, qr/^Mojo::IOLoop already running/, 'right error';
ok $server_running, 'loop is running';
ok $client_running, 'loop is running';
is $server, 'tset123', 'right content';
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/psgi.t
Expand Up @@ -34,7 +34,7 @@ post '/params' => sub {
};

# Binding
my $app = Mojo::Server::PSGI->new->to_psgi;
my $app = Mojo::Server::PSGI->new->to_psgi_app;
my $content = 'hello=world';
open my $body, '<', \$content;
my $env = {
Expand Down

0 comments on commit 1cb4e0b

Please sign in to comment.