Permalink
Browse files

Cleanup

  • Loading branch information...
1 parent 792ef85 commit d9c1aa6bf33dd45867f26a8014a3bdd83619529b @vti vti committed May 15, 2011
Showing with 37 additions and 18 deletions.
  1. +1 −1 lib/PocketIO/Connection.pm
  2. +14 −14 lib/PocketIO/Pool.pm
  3. +3 −3 lib/PocketIO/Transport/Base.pm
  4. +19 −0 t/pool.t
@@ -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
@@ -9,37 +9,27 @@ 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 {
my $self = shift;
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;
@@ -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
@@ -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);

0 comments on commit d9c1aa6

Please sign in to comment.