typester (owner)

Revisions

gist: 159159 Download_button fork
public
Public Clone URL: git://gist.github.com/159159.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
diff --git a/lib/AnyEvent/APNS.pm b/lib/AnyEvent/APNS.pm
index 5a5d20c..6ca18b4 100644
--- a/lib/AnyEvent/APNS.pm
+++ b/lib/AnyEvent/APNS.pm
@@ -59,11 +59,6 @@ has on_connect => (
 
 no Any::Moose;
 
-sub BUILD {
- my ($self) = @_;
- $self->_connect;
-}
-
 sub send {
     my $self = shift;
     my ($token, $payload) = @_;
@@ -87,10 +82,13 @@ sub _error_handler {
     $self->on_error(@_);
 }
 
-sub _connect {
+sub connect {
     my $self = shift;
 
- undef $self->{handler};
+ if ($self->handler) {
+ warn 'Already connected!';
+ return;
+ }
 
     my $host = $self->sandbox
         ? 'gateway.sandbox.push.apple.com'
diff --git a/t/01_simple.t b/t/01_simple.t
index a329706..7cd3fc8 100644
--- a/t/01_simple.t
+++ b/t/01_simple.t
@@ -49,10 +49,13 @@ tcp_server undef, $port, sub {
 
 # client XXX: a bit hacky
 no warnings 'redefine';
-*AnyEvent::APNS::_connect = sub {
+*AnyEvent::APNS::connect = sub {
     my $self = shift;
 
- undef $self->{handler};
+ if ($self->handler) {
+ warn 'Already connected!';
+ return;
+ }
 
     tcp_connect '127.0.0.1', $port, sub {
         my ($fh) = @_
@@ -75,5 +78,6 @@ my $apns; $apns = AnyEvent::APNS->new(
         $apns->send('d' x 32 => { foo => 'bar' });
     },
 );
+$apns->connect;
 
 $cv->recv;