Agent/Beeminder/Source.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 52 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Exobrain::Agent::Beeminder::Source;
2 use Moose;
3 use Method::Signatures;
4 use Try::Tiny;
5 use Dancer qw(set post warning debug status error dance params param);
6 use Data::Dumper;
7  
8 with 'Exobrain::Agent::Beeminder';
9 with 'Exobrain::Agent::Run';
10  
11 # ABSTRACT: Turn Beeminder callbacks into exobrain measurements
12 our $VERSION = '1.06'; # VERSION
13  
14  
15 method run() {
16  
17 # This is all Dancer configuration, because we run a little
18 # Dancer micro-instance.
19  
20 set port => 3000;
21 set logger => 'console';
22 set log => 'core';
23 set warnings => 1;
24  
25 post qr{.*} => sub {
26  
27 # If we see what could be a valid response, but it's not
28 # an 'ADD', then ignore it.
29 if( (param('action')||"") ne 'ADD') {
30 warning("Non-add packet received");
31 return "IGNORED";
32 }
33  
34 my $pktdump = Dumper ({ params() });
35 debug("Receieved packet: $pktdump");
36  
37 # Exobrain just accepts the packet whole.
38  
39 try {
40 debug("About to send packet on exobrain bus...");
41 $self->exobrain->measure( 'Beeminder', params(), raw => { params() } );
42 debug("Packet sent on exobrain bus");
43 }
44 catch {
45 error("Sending on exobrain bus failed: $_");
46 status 'error';
47 return "Invalid packet";
48 };
49  
50 return "OK";
51 };
52  
53 dance;
54 }
55  
56 1;
57  
58 __END__