Skip to content

Commit

Permalink
deprecated Mojo::IOLoop->connect_timeout in favor of timeout argument
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 16, 2011
1 parent 6c205e4 commit 2cd1fc9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -7,8 +7,11 @@ This file documents the revision history for Perl extension Mojolicious.
Mojo::IOLoop->timeout.
- Deprecated Mojo::IOLoop->write in favor of
Mojo::IOLoop::Stream->write.
- Deprecated Mojo::IOLoop->connect_timeout in favor of timeout
argument.
- Deprecated on_* methods in Mojo::IOLoop.
- Removed Mojo::IOLoop::Resolver.
- Added EXPERIMENTAL connect_timeout attribute to Mojo::UserAgent.
- Added EXPERIMENTAL is_readable method to Mojo::IOLoop::Stream.
- Added EXPERIMENTAL charset method to Mojo::Content.
- Added EXPERIMENTAL write event to Mojo::IOLoop::Stream.
Expand Down
30 changes: 18 additions & 12 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -13,9 +13,8 @@ use Time::HiRes 'time';

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

has client_class => 'Mojo::IOLoop::Client';
has connect_timeout => 3;
has iowatcher => sub {
has client_class => 'Mojo::IOLoop::Client';
has iowatcher => sub {
my $class = Mojo::IOWatcher->detect;
warn "MAINLOOP ($class)\n" if DEBUG;
$class->new;
Expand Down Expand Up @@ -66,8 +65,10 @@ sub client {
}
);

# DEPRECATED in Leaf Fluttering In Wind!
$args->{timeout} ||= $self->{connect_timeout};

# Connect
$args->{timeout} ||= $self->connect_timeout;
$client->connect($args);

return $id;
Expand Down Expand Up @@ -119,6 +120,19 @@ sub connect {
return $id;
}

# DEPRECATED in Leaf Fluttering In Wind!
sub connect_timeout {
my ($self, $timeout) = @_;
warn <<EOF;
Mojo::IOLoop->connect_timeout is DEPRECATED in favor of the timeout argument!
EOF
if ($timeout) {
$self->{connect_timeout} = $timeout;
return $self;
}
return $self->{connect_timeout};
}

# DEPRECATED in Leaf Fluttering In Wind!
sub connection_timeout {
warn <<EOF;
Expand Down Expand Up @@ -510,14 +524,6 @@ Class to be used for opening TCP connections with the C<client> method,
defaults to L<Mojo::IOLoop::Client>.
Note that this attribute is EXPERIMENTAL and might change without warning!
=head2 C<connect_timeout>
my $timeout = $loop->connect_timeout;
$loop = $loop->connect_timeout(5);
Maximum time in seconds a connection can take to be connected before being
dropped, defaults to C<3>.
=head2 C<iowatcher>
my $watcher = $loop->iowatcher;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/IOLoop/Client.pm
Expand Up @@ -234,7 +234,7 @@ Port to connect to.
=item C<timeout>
Maximum time in seconds a connection can take to be connected.
Maximum time in seconds establishing connection may take.
=item C<tls>
Expand Down
13 changes: 12 additions & 1 deletion lib/Mojo/UserAgent.pm
Expand Up @@ -14,7 +14,8 @@ use Scalar::Util 'weaken';
use constant DEBUG => $ENV{MOJO_USERAGENT_DEBUG} || 0;

# "You can't let a single bad experience scare you away from drugs."
has cert => sub { $ENV{MOJO_CERT_FILE} };
has cert => sub { $ENV{MOJO_CERT_FILE} };
has connect_timeout => 3;
has cookie_jar => sub { Mojo::CookieJar->new };
has [qw/http_proxy https_proxy no_proxy/];
has ioloop => sub { Mojo::IOLoop->new };
Expand Down Expand Up @@ -217,6 +218,7 @@ sub _connect {
address => $host,
port => $port,
handle => $id,
timeout => $self->connect_timeout,
tls => $scheme eq 'https' ? 1 : 0,
tls_cert => $self->cert,
tls_key => $self->key,
Expand Down Expand Up @@ -652,6 +654,15 @@ L<Mojo::UserAgent> implements the following attributes.
Path to TLS certificate file, defaults to the value of the C<MOJO_CERT_FILE>
environment variable.
=head2 C<connect_timeout>
my $timeout = $ua->connect_timeout;
$ua = $ua->connect_timeout(5);
Maximum amount of time in seconds establishing a connection may take,
defaults to C<3>.
Note that this attribute is EXPERIMENTAL and might change without warning!
=head2 C<cookie_jar>
my $cookie_jar = $ua->cookie_jar;
Expand Down

0 comments on commit 2cd1fc9

Please sign in to comment.