View/APNS.pm

filter: Statementstmt 91.6% 44 / 48 Branchbran 55.0% 11 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 83.3% 65 / 78 CC 13 SCAR 18.1
CC
13
Cov
81%
new
9.4
process
6.7
BEGIN
1.0
CRAP 6.1
↑ Summary Helper/View/APNS.pm »
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
BranchTrueFalseTotal
unless $field 0 4 4
19 4 ▶ next if $field ne 'apns';
Branch: 1 branch
BranchTrueFalseTotal
if $field ne "apns" 2 2 4
20 2 my $subs = $arguments->{$field};
21 2 for my $subfield ( keys(%$subs) ) {
22 6 ▶ if ( $self->can($subfield) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($subfield)) { } 6 0 6
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
BranchTrueFalseTotal
unless ($self->certification) 0 2 2
31 0 croak "Invalied certification";
32 }
33 2 ▶ unless ( $self->private_key ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->private_key) 0 2 2
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
BranchTrueFalseTotal
if ($self->passwd) 2 0 2
49 2 $notify->passwd( $self->passwd );
50 }
51 2 ▶ $notify->sandbox( $c->stash->{apns}->{sandbox} ) if $c->stash->{apns}->{sandbox};
Branch: 1 branch
BranchTrueFalseTotal
if $c->stash->{"apns"}{"sandbox"} 0 2 2
52 2 ▶ unless ( $c->stash->{apns}->{device_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->stash->{"apns"}{"device_token"}) 0 2 2
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
BranchTrueFalseTotal
if $c->stash->{"apns"}{"badge"} 2 0 2
58 2 ▶ $notify->badge( $c->stash->{apns}->{badge} ) if $c->stash->{apns}->{badge};
Branch: 1 branch
BranchTrueFalseTotal
if $c->stash->{"apns"}{"badge"} 2 0 2
59 2 $notify->write;
60 }
61  
62 3 1;
63 __END__
↑ Summary Helper/View/APNS.pm »