Simple.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 49 CC 2 SCAR 10.0
CC
2
Cov
0%
call
6.0
new
2.0
next_id
2.0
CRAP 2.7
1 package Finance::TWS::Simple;
2  
3 # ABSTRACT: simple InteractiveBrokers API (blocking abstraction over AnyEvent::TWS)
4  
5 use strict;
6 use warnings;
7  
8 use AnyEvent;
9 use AnyEvent::TWS;
10  
11  
12 sub new {
13 my ($class, %arg) = @_;
14  
15 my $self = bless {}, $class;
16  
17 # connect to TWS
18 $self->{tws} = AnyEvent::TWS->new(%arg);
19 $self->{tws}->connect->recv;
20  
21 return $self;
22 }
23  
24 sub next_id { (shift)->{tws}->next_valid_id }
25  
26 sub ae_call {
27 my ($self, $object, $request) = @_;
28  
29 $self->{tws}->call($request, sub { $object->cb(shift) });
30 }
31  
32 sub call {
33 my ($self, $name, $arg) = @_;
34  
35 my $cv = AE::cv;
36 my $class = 'Finance::TWS::Simple::' . $name;
37 eval "use $class"; die $@ if $@;
38 $class->call($self, $cv, $arg);
39  
40 return $cv->recv;
41 }
42  
43 sub struct { return (shift)->{tws}->struct(@_) }
44 sub request { return (shift)->{tws}->request(@_) }
45  
46 1;
47  
48  
49 __END__