Show
Ignore:
Timestamp:
10/11/09 16:49:00 (5 years ago)
Author:
haoyayoi
Message:

wrote pod and some fix

Location:
lang/perl/Catalyst-View-APNS/trunk
Files:
3 added
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Catalyst-View-APNS/trunk/MANIFEST.SKIP

    r35573 r35574  
     1^\.git/ 
    12\bRCS\b 
    23\bCVS\b 
  • lang/perl/Catalyst-View-APNS/trunk/Makefile.PL

    r35573 r35574  
    88author_tests 'xt'; 
    99 
     10requires 'AnyEvent::APNS'; 
     11 
    1012build_requires 'Test::More'; 
    1113use_test_base; 
  • lang/perl/Catalyst-View-APNS/trunk/lib/Catalyst/View/APNS.pm

    r35573 r35574  
    33use strict; 
    44use warnings; 
     5use base qw/ Catalyst::View /; 
     6use AnyEvent::APNS; 
    57our $VERSION = '0.01'; 
     8 
     9__PACKAGE__->mk_accessors(qw/apns cv/); 
     10 
     11sub new { 
     12    my ( $class, $c, $arguments ) = @_; 
     13    my $self => $class->next::method($c); 
     14     
     15    my $cv = AnyEvent->condvar; 
     16    $self->cv($cv); 
     17 
     18    my $apns; 
     19    if (my $args = $self->{apns}) { 
     20        if (ref($args) eq 'HASH') { 
     21            $self->{apns}->{sandbox} = 0 
     22                unless $self->{apns}->{sandbox}; 
     23            $apns = AnyEvent::APNS->new( 
     24                certificate => $self->{apns}->{certification}, 
     25                private_key => $self->{apns}->{private_key}, 
     26                sandbox     => $self->{apns}->{sandbox}, 
     27            ); 
     28        } else { 
     29            croak "Invalid new specified, check pod for AnyEvent::APNS"; 
     30        } 
     31    } 
     32    $self->apns($apns); 
     33    return $self; 
     34} 
     35 
     36sub process { 
     37    my ( $self, $c ) = @_; 
     38    croak "Unable to push notification, bad apns configuration" 
     39        unless $self->apns; 
     40    croak "Invalid payload specified, check pod for AnyEvent::APNS" 
     41        unless (ref($c->{apns}->{payload}) eq 'HASH'); 
     42    $self->apns->connect; 
     43    $self->apns->send( $c->{apns}->{device_token}, $c->{apns}->{payload} ); 
     44    $self->apns->handler->on_drain( 
     45        sub { 
     46            undef $_[0]; 
     47            $self->cv->send; 
     48        } 
     49    ); 
     50    $self->cv->recv; 
     51} 
    652 
    7531; 
     
    1056=head1 NAME 
    1157 
    12 Catalyst::View::APNS - 
     58Catalyst::View::APNS - APNS View Class. 
    1359 
    1460=head1 SYNOPSIS 
    1561 
    16   use Catalyst::View::APNS; 
     62# lib/MyApp/View/APNS.pm 
     63package MyApp::View::APNS; 
     64use base qw/Catalyst::View::APNS/; 
     651; 
     66 
     67# Configure in lib/MyApp.pm 
     68MyApp->config({ 
     69    apns => { 
     70        certification => cert #require to specify 
     71        private_key   => key  #require to specify 
     72        sandbox       => 0|1  #optional 
     73    } 
     74}); 
     75 
     76sub hello : Local { 
     77    my ( $self, $c ) = @_; 
     78    $c->stash->{apns}->{device_token} = $device_token; 
     79    $c->stash->{apns}->{payload} = $payload; 
     80    $c->forward('MyApp::View::APNS'); 
     81} 
     82 
     83Use the helper to create your View: 
     84  
     85    myapp_create.pl view APNS APNS 
    1786 
    1887=head1 DESCRIPTION 
    1988 
    20 Catalyst::View::APNS is 
     89Catalyst::View::APNS is Catalyst view handler that Apple Push Notification Service. 
    2190 
    2291=head1 AUTHOR