Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup

  • Loading branch information...
commit d9c1aa6bf33dd45867f26a8014a3bdd83619529b 1 parent 792ef85
@vti vti authored
View
2  lib/PocketIO/Connection.pm
@@ -210,7 +210,7 @@ sub send_broadcast {
my ($message) = @_;
my @conn = grep { $_->is_connected && $_->id ne $self->id }
- PocketIO::Pool->instance->connections;
+ PocketIO::Pool->connections;
foreach my $conn (@conn) {
$conn->send_message($message);
View
28 lib/PocketIO/Pool.pm
@@ -9,29 +9,19 @@ use PocketIO::Connection;
use constant DEBUG => $ENV{POCKETIO_POOL_DEBUG};
-sub instance {
- my $class = shift;
-
- no strict;
-
- ${"$class\::_instance"} ||= $class->_new_instance(@_);
-
- return ${"$class\::_instance"};
-}
-
sub find_connection {
my $self = shift;
my ($conn) = @_;
my $id = blessed $conn ? $conn->id : $conn;
- return $self->{connections}->{$id};
+ return $self->_instance->{connections}->{$id};
}
sub connections {
my $self = shift;
- return values %{$self->{connections}};
+ return values %{$self->_instance->{connections}};
}
sub add_connection {
@@ -39,7 +29,7 @@ sub add_connection {
my $conn = $self->_build_connection(@_);
- $self->{connections}->{$conn->id} = $conn;
+ $self->_instance->{connections}->{$conn->id} = $conn;
$conn->connecting;
@@ -54,11 +44,21 @@ sub remove_connection {
my $id = blessed $conn ? $conn->id : $conn;
- delete $self->{connections}->{$id};
+ delete $self->_instance->{connections}->{$id};
DEBUG && warn "Removed connection '" . $id . "'\n";
}
+sub _instance {
+ my $class = shift;
+
+ no strict;
+
+ ${"$class\::_instance"} ||= $class->_new_instance(@_);
+
+ return ${"$class\::_instance"};
+}
+
sub _new_instance {
my $class = shift;
View
6 lib/PocketIO/Transport/Base.pm
@@ -29,7 +29,7 @@ sub env { shift->{req}->{env} }
sub add_connection {
my $self = shift;
- return PocketIO::Pool->instance->add_connection(
+ return PocketIO::Pool->add_connection(
type => $self->name,
@_
);
@@ -39,7 +39,7 @@ sub remove_connection {
my $self = shift;
my ($conn) = @_;
- PocketIO::Pool->instance->remove_connection(
+ PocketIO::Pool->remove_connection(
$conn->id);
return $self;
@@ -48,7 +48,7 @@ sub remove_connection {
sub find_connection {
my $self = shift;
- return PocketIO::Pool->instance->find_connection(@_);
+ return PocketIO::Pool->find_connection(@_);
}
sub client_connected {
View
19 t/pool.t
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+
+use Test::More tests => 6;
+
+use_ok('PocketIO::Pool');
+
+is_deeply [PocketIO::Pool->connections], [];
+
+ok! PocketIO::Pool->find_connection(123);
+
+my $conn = PocketIO::Pool->add_connection();
+ok $conn;
+
+is $conn->id, PocketIO::Pool->find_connection($conn->id)->id;
+
+PocketIO::Pool->remove_connection($conn->id);
+
+ok! PocketIO::Pool->find_connection($conn->id);
Please sign in to comment.
Something went wrong with that request. Please try again.