Created
          July 31, 2009 09:47 
        
      - 
      
- 
        Save typester/159159 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment