| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::Pushover; | 
| 2 |  |  |  |  |  |  | # ABSTRACT: Net::Pushover - The Pushover API client implementation | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | # pragmas | 
| 5 | 3 |  |  | 3 |  | 37178 | use 5.10.0; | 
|  | 3 |  |  |  |  | 9 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | # imports | 
| 8 | 3 |  |  | 3 |  | 1629 | use Moo; | 
|  | 3 |  |  |  |  | 32859 |  | 
|  | 3 |  |  |  |  | 16 |  | 
| 9 | 3 |  |  | 3 |  | 3727 | use Carp; | 
|  | 3 |  |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 163 |  | 
| 10 | 3 |  |  | 3 |  | 1393 | use JSON; | 
|  | 3 |  |  |  |  | 24455 |  | 
|  | 3 |  |  |  |  | 17 |  | 
| 11 | 3 |  |  | 3 |  | 2263 | use LWP::UserAgent; | 
|  | 3 |  |  |  |  | 104119 |  | 
|  | 3 |  |  |  |  | 605 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | # accessors | 
| 15 |  |  |  |  |  |  | has token => (is => 'rw'); | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | has user  => (is => 'rw'); | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | has _ua   => ( | 
| 20 |  |  |  |  |  |  | is => 'ro', default => sub { | 
| 21 |  |  |  |  |  |  | my $ua = LWP::UserAgent->new; | 
| 22 |  |  |  |  |  |  | $ua->agent('Net-Pushover/0.001 Perl API Client'); | 
| 23 |  |  |  |  |  |  | return $ua; | 
| 24 |  |  |  |  |  |  | } | 
| 25 |  |  |  |  |  |  | ); | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | # methods | 
| 29 |  |  |  |  |  |  | sub message { | 
| 30 | 3 |  |  | 3 | 1 | 4473 | my ($self, $args) = (shift, {@_}); | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | # auth validation | 
| 33 | 3 |  |  |  |  | 8 | $self->_auth_validation; | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | # required fields | 
| 36 |  |  |  |  |  |  | Carp::confess("Field text is required for message body") | 
| 37 | 3 | 100 |  |  |  | 114 | unless  $args->{text}; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 2 |  |  |  |  | 6 | $args->{user}    = $self->user; | 
| 40 | 2 |  |  |  |  | 4 | $args->{token}   = $self->token; | 
| 41 | 2 |  |  |  |  | 4 | $args->{message} = delete $args->{text}; | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | # sending data | 
| 44 | 2 |  |  |  |  | 10 | my $res = $self->_ua->post( | 
| 45 |  |  |  |  |  |  | 'https://api.pushover.net/1/messages.json', $args | 
| 46 |  |  |  |  |  |  | ); | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 2 |  |  |  |  | 18 | return JSON::decode_json($res->decoded_content) | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | sub _auth_validation { | 
| 52 | 6 |  |  | 6 |  | 6492 | my $self = shift; | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | # auth exception | 
| 55 | 6 | 100 |  |  |  | 200 | Carp::confess("Error: token is undefined") unless $self->token; | 
| 56 | 5 | 100 |  |  |  | 112 | Carp::confess("Error: user is undefined") unless $self->user; | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 4 |  |  |  |  | 7 | return 1; | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | 1; | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | __END__ |