Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
deprecated Mojo::Home->app_class, Mojo::IOLoop->client_class, Mojo::I…
…OLoop->server_class and Mojo::IOLoop->stream_class
  • Loading branch information
kraih committed Jul 20, 2012
1 parent 093bcb1 commit 10c2fc3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 54 deletions.
4 changes: 4 additions & 0 deletions Changes
@@ -1,5 +1,9 @@

3.12 2012-07-20
- Deprecated Mojo::Home->app_class.
- Deprecated Mojo::IOLoop->client_class.
- Deprecated Mojo::IOLoop->server_class.
- Deprecated Mojo::IOLoop->stream_class.
- Deprecated Mojo::Message->dom_class.
- Deprecated Mojo::Message->json_class.
- Added json method to Mojo::UserAgent::Transactor.
Expand Down
23 changes: 8 additions & 15 deletions lib/Mojo/Home.pm
Expand Up @@ -12,18 +12,18 @@ use File::Spec::Functions qw(abs2rel catdir catfile splitdir);
use FindBin;
use Mojo::Util qw(class_to_path slurp);

has app_class => 'Mojo::HelloWorld';

# "I'm normally not a praying man, but if you're up there,
# please save me Superman."
sub new { shift->SUPER::new->parse(@_) }

sub detect {
my ($self, $class) = @_;
# DEPRECATED in Rainbow!
sub app_class {
warn "Mojo::Home->app_class is DEPRECATED!\n";
return @_ > 1 ? shift : 'Mojo::HelloWorld';
}

# Class
$self->app_class($class) if $class;
$class ||= $self->app_class;
sub detect {
my $self = shift;

# Environment variable
if ($ENV{MOJO_HOME}) {
Expand All @@ -32,7 +32,7 @@ sub detect {
}

# Try to find home from lib directory
if ($class) {
if (my $class = @_ ? shift : 'Mojo::HelloWorld') {
my $file = class_to_path $class;
if (my $path = $INC{$file}) {
$path =~ s/$file$//;
Expand Down Expand Up @@ -119,13 +119,6 @@ L<Mojo::Home> is a container for home directories.
L<Mojo::Home> implements the following attributes.
=head2 C<app_class>
my $class = $home->app_class;
$home = $home->app_class('Foo::Bar');
Application class.
=head1 METHODS
L<Mojo::Home> inherits all methods from L<Mojo::Base> and implements the
Expand Down
61 changes: 25 additions & 36 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -14,7 +14,6 @@ use Time::HiRes 'time';
use constant DEBUG => $ENV{MOJO_IOLOOP_DEBUG} || 0;

has accept_interval => 0.025;
has client_class => 'Mojo::IOLoop::Client';
has [qw(lock unlock)];
has max_accepts => 0;
has max_connections => 1000;
Expand All @@ -23,8 +22,6 @@ has reactor => sub {
warn "-- Reactor initialized ($class)\n" if DEBUG;
return $class->new;
};
has server_class => 'Mojo::IOLoop::Server';
has stream_class => 'Mojo::IOLoop::Stream';

# Ignore PIPE signal
$SIG{PIPE} = 'IGNORE';
Expand All @@ -41,7 +38,7 @@ sub client {
$self->_manage;

# New client
my $client = $self->client_class->new;
my $client = Mojo::IOLoop::Client->new;
my $id = $self->_id;
my $c = $self->{connections}{$id} ||= {};
$c->{client} = $client;
Expand All @@ -56,7 +53,7 @@ sub client {
# New stream
my $c = $self->{connections}{$id};
delete $c->{client};
my $stream = $c->{stream} = $self->stream_class->new($handle);
my $stream = $c->{stream} = Mojo::IOLoop::Stream->new($handle);
$self->_stream($stream => $id);

# Connected
Expand All @@ -74,6 +71,12 @@ sub client {
return $id;
}

# DEPRECATED in Rainbow!
sub client_class {
warn "Mojo::IOLoop->client_class is DEPRECATED!\n";
return @_ > 1 ? shift : 'Mojo::IOLoop::Client';
}

sub delay {
my ($self, $cb) = @_;
$self = $self->singleton unless ref $self;
Expand Down Expand Up @@ -123,7 +126,7 @@ sub server {
$self->_manage;

# New server
my $server = $self->server_class->new;
my $server = Mojo::IOLoop::Server->new;
my $id = $self->_id;
$self->{servers}{$id} = $server;
weaken $server->reactor($self->reactor)->{reactor};
Expand All @@ -135,7 +138,7 @@ sub server {
my $handle = pop;

# Accept
my $stream = $self->stream_class->new($handle);
my $stream = Mojo::IOLoop::Stream->new($handle);
my $id = $self->stream($stream);
$self->$cb($stream, $id);

Expand All @@ -157,6 +160,12 @@ sub server {
return $id;
}

# DEPRECATED in Rainbow!
sub server_class {
warn "Mojo::IOLoop->server_class is DEPRECATED!\n";
return @_ > 1 ? shift : 'Mojo::IOLoop::Server';
}

sub singleton { state $loop ||= shift->SUPER::new }

sub start {
Expand Down Expand Up @@ -184,6 +193,12 @@ sub stream {
return $c->{stream};
}

# DEPRECATED in Rainbow!
sub stream_class {
warn "Mojo::IOLoop->stream_class is DEPRECATED!\n";
return @_ > 1 ? shift : 'Mojo::IOLoop::Stream';
}

sub timer {
my ($self, $after, $cb) = @_;
$self = $self->singleton unless ref $self;
Expand Down Expand Up @@ -368,14 +383,6 @@ Interval in seconds for trying to reacquire the accept mutex and connection
management, defaults to C<0.025>. Note that changing this value can affect
performance and idle cpu usage.
=head2 C<client_class>
my $class = $loop->client_class;
$loop = $loop->client_class('Mojo::IOLoop::Client');
Class to be used for opening TCP connections with the C<client> method,
defaults to L<Mojo::IOLoop::Client>.
=head2 C<lock>
my $cb = $loop->lock;
Expand Down Expand Up @@ -428,22 +435,6 @@ L<Mojo::Reactor::EV> object.
say $writable ? 'Handle is writable' : 'Handle is readable';
});
=head2 C<server_class>
my $class = $loop->server_class;
$loop = $loop->server_class('Mojo::IOLoop::Server');
Class to be used for accepting TCP connections with the C<server> method,
defaults to L<Mojo::IOLoop::Server>.
=head2 C<stream_class>
my $class = $loop->stream_class;
$loop = $loop->stream_class('Mojo::IOLoop::Stream');
Class to be used by C<client> and C<server> methods for I/O streams, defaults
to L<Mojo::IOLoop::Stream>.
=head2 C<unlock>
my $cb = $loop->unlock;
Expand All @@ -464,8 +455,7 @@ following new ones.
my $id = $loop->client(address => '127.0.0.1', port => 3000, sub {...});
my $id = $loop->client({address => '127.0.0.1', port => 3000}, sub {...});
Open TCP connection with C<client_class>, which is usually
L<Mojo::IOLoop::Client>, takes the same arguments as
Open TCP connection with L<Mojo::IOLoop::Client>, takes the same arguments as
L<Mojo::IOLoop::Client/"connect">.
# Connect to localhost on port 3000
Expand Down Expand Up @@ -545,9 +535,8 @@ them to finish writing all data in their write buffers.
my $id = $loop->server(port => 3000, sub {...});
my $id = $loop->server({port => 3000}, sub {...});
Accept TCP connections with C<server_class>, which is usually
L<Mojo::IOLoop::Server>, takes the same arguments as
L<Mojo::IOLoop::Server/"listen">.
Accept TCP connections with L<Mojo::IOLoop::Server>, takes the same arguments
as L<Mojo::IOLoop::Server/"listen">.
# Listen on port 3000
Mojo::IOLoop->server({port => 3000} => sub {
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/home.t
Expand Up @@ -35,7 +35,7 @@ is_deeply [split /\\|\//, canonpath($home->to_string)],
[split /\\|\//, canonpath(realpath cwd())], 'right path detected';

# FindBin detection
$home = Mojo::Home->new->app_class(undef)->detect;
$home = Mojo::Home->new->detect(undef);
is_deeply [split /\\|\//, catdir(splitdir($FindBin::Bin))],
[split /\\|\//, $home], 'right path detected';

Expand Down
2 changes: 1 addition & 1 deletion t/mojo/ioloop.t
Expand Up @@ -156,7 +156,7 @@ Mojo::IOLoop->client(
}
);
$handle = $delay->wait->steal_handle;
my $stream = Mojo::IOLoop->singleton->stream_class->new($handle);
my $stream = Mojo::IOLoop::Stream->new($handle);
$id = Mojo::IOLoop->stream($stream);
$stream->on(close => sub { Mojo::IOLoop->stop });
$stream->on(read => sub { $buffer .= pop });
Expand Down
6 changes: 5 additions & 1 deletion t/pod_coverage.t
Expand Up @@ -6,6 +6,10 @@ plan skip_all => 'set TEST_POD to enable this test (developer only!)'
plan skip_all => 'Test::Pod::Coverage 1.04 required for this test!'
unless eval 'use Test::Pod::Coverage 1.04; 1';

# DEPRECATED in Rainbow!
my @rainbow
= qw(app_class client_class dom_class json_class server_class stream_class);

# "Marge, I'm going to miss you so much. And it's not just the sex.
# It's also the food preparation."
all_pod_coverage_ok({also_private => [qw(dom_class json_class)]});
all_pod_coverage_ok({also_private => [@rainbow]});

0 comments on commit 10c2fc3

Please sign in to comment.