lib/App/Standby/Service/Pingdom.pm

filter: Statementstmt 61.2% 30 / 49 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 64.2% 9 / 14 Podpod n/a totaltotal 60.0% 39 / 65 CC 3 SCAR 8.9
CC
3
Cov
59%
_update
6.0
__ANON__
6.0
_init_pingdom_contact_ids
2.0
CRAP 2.4
« lib/App/Standby.pm ↑ Summary lib/App/Standby/Cmd/Command/bootstrap.pm »
1 package App::Standby::Service::Pingdom;
2 2 $App::Standby::Service::Pingdom::VERSION = '0.04';
3 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 $App::Standby::Service::Pingdom::AUTHORITY = 'cpan:TEX';
5 }
6 # ABSTRACT: Pingdom Service
7  
8 2 ▶use 5.010_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use feature ':5.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # use IO::Handle;
16 # use autodie;
17 # use MooseX::Params::Validate;
18 # use Carp;
19 # use English qw( -no_match_vars );
20 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Pingdom::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # extends ...
24 2 extends 'App::Standby::Service';
25 # has ...
26 2 has 'pingdom_contact_ids' => (
27 'is' => 'rw',
28 'isa' => 'ArrayRef',
29 'lazy' => 1,
30 'builder' => '_init_pingdom_contact_ids',
31 );
32  
33 2 has 'pingdom' => (
34 'is' => 'rw',
35 'isa' => 'Pingdom::Client',
36 'lazy' => 1,
37 'builder' => '_init_pingdom',
38 );
39 # with ...
40 # initializers ...
41 0 ▶sub _init_pingdom_contact_ids {
Subroutine _init_pingdom_contact_ids: not called CC=1 SCAR=6.9
42 0 my $self = shift;
43  
44 0 return $self->_config_values($self->name().'_contact_id');
45 }
46  
47 0 ▶sub _init_pingdom {
Subroutine _init_pingdom: not called CC=1 SCAR=6.9
48 0 my $self = shift;
49  
50 0 my $username = $self->_config_values($self->name().'_username')->[0];
51 0 my $password = $self->_config_values($self->name().'_password')->[0];
52 0 my $apikey = $self->_config_values($self->name().'_apikey')->[0];
53  
54 0 my $Pingdom = Pingdom::Client::->new({
55 'username' => $username,
56 'password' => $password,
57 'apikey' => $apikey,
58 });
59  
60 0 return $Pingdom;
61 }
62  
63 # your code here ...
64 0 ▶sub _update {
Subroutine _update: not called CC=2 SCAR=17.9
65 0 my $self = shift;
66 0 my $user_ref = shift;
67  
68 # set the contact number for each listed contact to the first person
69 # in the user list (remember: the first person always is the one currently
70 # on duty)
71 0 foreach my $contact_id (@{$self->pingdom_contact_ids()}) {
72 0 ▶ try {
Subroutine __ANON__: not called CC=2 SCAR=17.9
73 my $status = $self->pingdom()->contact_modify($contact_id, {
74 0 'cellphone' => $user_ref->[0]->{'cellphone'},
75 'countrycode' => 49,
76 'countryiso' => 'DE',
77 });
78 0 ▶ if($status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status) { } 0 0 0
79 0 $self->logger()->log( message => "Successfully updated pingdom contact id $contact_id", level => 'debug', );
80 } else {
81 $self->logger()->log(
82 message => "Failed to update pingdom contact id $contact_id. Error: ".
83 $self->pingdom()->lasterror()->{'statuscode'}.' - '.
84 $self->pingdom()->lasterror()->{'statusdesc'}.' - '.
85 0 $self->pingdom()->lasterror()->{'errormessage'},
86 level => 'error',
87 );
88 }
89 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 0 $self->logger()->log( message => "Failed to update contact id ".$contact_id. " w/ error: ".$_, level => 'warning', );
91 0 };
92 }
93  
94 0 return 1;
95 }
96  
97 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 2 __PACKAGE__->meta->make_immutable;
99  
100 2 1;
101  
102 __END__
103  
104 =pod
105  
106 =encoding utf-8
107  
108 =head1 NAME
109  
110 App::Standby::Service::Pingdom - Pingdom Service
111  
112 =head1 NAME
113  
114 App::Standby::Service::Pingdom - Pingdom Service
115  
116 =head1 AUTHOR
117  
118 Dominik Schulz <dominik.schulz@gauner.org>
119  
120 =head1 COPYRIGHT AND LICENSE
121  
122 This software is copyright (c) 2012 by Dominik Schulz.
123  
124 This is free software; you can redistribute it and/or modify it under
125 the same terms as the Perl 5 programming language system itself.
126  
127 =cut
« lib/App/Standby.pm ↑ Summary lib/App/Standby/Cmd/Command/bootstrap.pm »