lib/App/MadEye/Plugin/Notify/IMKayac.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 63 CC 3 SCAR 15.5
CC
3
Cov
0%
notify
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 4.7
1 package App::MadEye::Plugin::Notify::IMKayac;
2 use strict;
3 use warnings;
4 use base qw/App::MadEye::Plugin::Base/;
5 use Params::Validate;
6 use MIME::Lite;
7 use DateTime;
8 use LWP::UserAgent;
9 use Digest::SHA1;
10  
11 sub notify : Hook {
12 my ($self, $context, $args) = @_;
13  
14 my $conf = $self->{config}->{config};
15 my $username = $conf->{username} or die "missing username";
16  
17 while (my ($plugin, $results) = each %$args) {
18 $plugin =~ s/.+::Agent:://;
19 my $msg = "ME: $plugin: ";
20 for my $result (@$results) {
21 $msg .= "'$result->{target}': $result->{message} ";
22 }
23  
24 my $params = {message => $msg};
25 if (my $secret_key = $conf->{secret_key}) {
26 $params->{sig} = sha1_hex($msg . $secret_key);
27 }
28 if (my $password = $conf->{password}) {
29 $params->{password} = $password;
30 }
31  
32 my $ua = LWP::UserAgent->new(timeout => 5, agent => "MadEye/$App::MadEye::VERSION");
33 my $res = $ua->post("http://im.kayac.com/api/post/$username", $params);
34 $res->is_success or die $res->status_line;
35 }
36 }
37  
38 1;