AnyEvent-APNS
view release on metacpan or search on metacpan
inc/Spiffy.pm view on Meta::CPAN
my $filter_dump = 0;
my $filter_save = 0;
our $filter_result = '';
sub import {
no strict 'refs';
no warnings;
my $self_package = shift;
# XXX Using parse_arguments here might cause confusion, because the
# subclass's boolean_arguments and paired_arguments can conflict, causing
# difficult debugging. Consider using something truly local.
my ($args, @export_list) = do {
local *boolean_arguments = sub {
qw(
-base -Base -mixin -selfless
-XXX -dumper -yaml
-filter_dump -filter_save
)
};
local *paired_arguments = sub { qw(-package) };
$self_package->parse_arguments(@_);
inc/Test/Base.pm view on Meta::CPAN
$block->seq_num($seq++);
}
return $blocks;
}
sub _choose_blocks {
my $blocks = [];
for my $hunk (@_) {
my $block = $self->_make_block($hunk);
if (exists $block->{ONLY}) {
diag "I found ONLY: maybe you're debugging?"
unless $self->_no_diag_on_only;
return [$block];
}
next if exists $block->{SKIP};
push @$blocks, $block;
if (exists $block->{LAST}) {
return $blocks;
}
}
return $blocks;
lib/AnyEvent/APNS.pm view on Meta::CPAN
is => 'rw',
isa => 'CodeRef',
default => sub { sub {} },
);
has on_error_response => (
is => 'rw',
isa => 'CodeRef',
);
has debug_port => (
is => 'rw',
isa => 'Int',
predicate => 'is_debug',
);
has _con_guard => (
is => 'rw',
isa => 'Object',
);
has last_identifier => (
is => 'rw',
isa => 'Int',
lib/AnyEvent/APNS.pm view on Meta::CPAN
if ($self->connected && $self->handler) {
warn 'Already connected!';
return;
}
my $host = $self->sandbox
? 'gateway.sandbox.push.apple.com'
: 'gateway.push.apple.com';
my $port = 2195;
if ($self->is_debug) {
$host = '127.0.0.1';
$port = $self->debug_port;
}
my $g = tcp_connect $host, $port, sub {
my ($fh) = @_
or return $self->on_error->(undef, 1, $!);
my $tls_setting = {};
if (ref $self->certificate) {
$tls_setting->{cert} = ${ $self->certificate };
}
else {
lib/AnyEvent/APNS.pm view on Meta::CPAN
$tls_setting->{key_file} = $self->private_key;
}
my $handle = AnyEvent::Handle->new(
fh => $fh,
on_error => sub {
$self->on_error->(@_);
$self->clear_handler;
$_[0]->destroy;
},
!$self->is_debug ? (
tls => 'connect',
tls_ctx => $tls_setting,
) : (),
);
$self->handler( $handle );
if ($self->on_eof) {
$handle->on_eof(sub {
$self->on_eof->(@_);
$self->clear_handler;
t/01_simple.t view on Meta::CPAN
use Test::Time; # to fix expiry
plan tests => 9;
use AnyEvent::APNS;
use AnyEvent::Socket;
my $port = empty_port;
my $apns; $apns = AnyEvent::APNS->new(
debug_port => $port,
certificate => 'dummy',
private_key => 'dummy',
on_error => sub { die $! },
on_connect => sub {
my $identifier = $apns->send('d' x 32 => { foo => 'bar' });
is( $identifier, 1, '1st identifier is 1' );
},
);
my $cv = AnyEvent->condvar;
t/02_trim.t view on Meta::CPAN
my $port = empty_port;
my $payloads = [
{ aps => { alert => 'ããã«ã¡ã¯'x100, } },
{ aps => { alert => { body => 'ããã«ã¡ã¯'x100, } } },
];
for my $payload (@$payloads) {
my $apns; $apns = AnyEvent::APNS->new(
debug_port => $port,
certificate => 'dummy',
private_key => 'dummy',
on_error => sub { die $! },
on_connect => sub {
$apns->send('d' x 32 => $payload);
},
);
my $cv = AnyEvent->condvar;
t/03_validate.t view on Meta::CPAN
use Test::Exception;
use Test::TCP;
plan tests => 4;
my $port = empty_port;
lives_ok {
my $apns; $apns = AnyEvent::APNS->new(
debug_port => $port,
certificate => 'dummy',
private_key => 'dummy',
);
} 'set certificate and private_key ok';
lives_ok {
my $apns; $apns = AnyEvent::APNS->new(
debug_port => $port,
certificate => \'dummy',
private_key => \'dummy',
);
} 'set certificate ref and private_key ref ok';
throws_ok {
my $apns; $apns = AnyEvent::APNS->new(
debug_port => $port,
private_key => 'dummy',
);
} qr/certificate.+is required/
, 'not set certificate';
throws_ok {
my $apns; $apns = AnyEvent::APNS->new(
debug_port => $port,
certificate => 'dummy',
);
} qr/private_key.+is required/
, 'not set private_key';
or die $!;
# close immediately
close $fh;
};
# without on_eof
$cv = AnyEvent->condvar;
my $apns; $apns = AnyEvent::APNS->new(
debug_port => $port,
certificate => \'',
private_key => \'',
on_error => sub {
my ($h, $fatal, $msg) = @_;
like $msg, qr/^Unexpected end-of-file/, 'eof ok';
$cv->send;
},
);
$apns->connect;
$cv->recv;
# on_eof
$cv = AnyEvent->condvar;
$apns = AnyEvent::APNS->new(
debug_port => $port,
certificate => \'',
private_key => \'',
on_error => sub {
my ($h, $fatal, $msg) = @_;
fail 'on_eof not called: ' . $msg;
$cv->send;
},
on_eof => sub {
my ($h) = @_;
pass 'on_eof called ok';
( run in 0.574 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )