| 1 | package Catalyst::View::APNS; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use Net::APNS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use base qw( Catalyst::View ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use Catalyst::Exception; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | our $VERSION = '0.01'; | |||||||||
| 10 | |||||||||||
| 11 | 3 | __PACKAGE__->mk_accessors(qw(apns cv certification private_key passwd)); | |||||||||
| 12 | |||||||||||
| 13 | 2 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=8 SCAR=22.4
Pod
documented
| |||||||||||
| 14 | 2 | my ( $class, $c, $arguments ) = @_; | |||||||||
| 15 | 2 | my $self = $class->next::method($c); | |||||||||
| 16 | |||||||||||
| 17 | 2 | for my $field ( keys(%$arguments) ) { | |||||||||
| 18 | 4 | ▶ | next unless $field; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 4 | ▶ | next if $field ne 'apns'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 2 | my $subs = $arguments->{$field}; | |||||||||
| 21 | 2 | for my $subfield ( keys(%$subs) ) { | |||||||||
| 22 | 6 | ▶ | if ( $self->can($subfield) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 6 | $self->$subfield( $subs->{$subfield} ); | |||||||||
| 24 | } | ||||||||||
| 25 | else { | ||||||||||
| 26 | 0 | $c->log->debug( "Invalied parameter " . $subfield ); | |||||||||
| 27 | } | ||||||||||
| 28 | } | ||||||||||
| 29 | } | ||||||||||
| 30 | 2 | ▶ | unless ( $self->certification ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | croak "Invalied certification"; | |||||||||
| 32 | } | ||||||||||
| 33 | 2 | ▶ | unless ( $self->private_key ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | croak "Invalied private_key"; | |||||||||
| 35 | } | ||||||||||
| 36 | 2 | return $self; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 2 | ▶ | sub process { | ||||||||
|
Subroutine
process: called CC=6 SCAR=19.1
Pod
documented
| |||||||||||
| 40 | 2 | my ( $self, $c ) = @_; | |||||||||
| 41 | 2 | my $apns = Net::APNS->new; | |||||||||
| 42 | 2 | my $notify = $apns->notify( | |||||||||
| 43 | { | ||||||||||
| 44 | cert => $self->certification, | ||||||||||
| 45 | key => $self->private_key, | ||||||||||
| 46 | } | ||||||||||
| 47 | ); | ||||||||||
| 48 | 2 | ▶ | if ( $self->passwd ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 2 | $notify->passwd( $self->passwd ); | |||||||||
| 50 | } | ||||||||||
| 51 | 2 | ▶ | $notify->sandbox( $c->stash->{apns}->{sandbox} ) if $c->stash->{apns}->{sandbox}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 2 | ▶ | unless ( $c->stash->{apns}->{device_token} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | croak "Invalied device token"; | |||||||||
| 54 | } | ||||||||||
| 55 | 2 | $notify->devicetoken( $c->stash->{apns}->{device_token} ); | |||||||||
| 56 | $notify->message( $c->stash->{apns}->{message} ) | ||||||||||
| 57 | 2 | ▶ | if $c->stash->{apns}->{badge}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 2 | ▶ | $notify->badge( $c->stash->{apns}->{badge} ) if $c->stash->{apns}->{badge}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 2 | $notify->write; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 3 | 1; | |||||||||
| 63 | __END__ | ||||||||||