Cellucidate/Base.pm

filter: Statementstmt 84.7% 61 / 72 Branchbran 70.0% 7 / 10 Conditioncond 54.5% 6 / 11 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 72.2% 13 / 18 Podpod 0.0% 0 / 14 totaltotal 67.1% 88 / 131 CC 12 SCAR 10.9
CC
12
Cov
80%
args
7.1
rest
4.0
formulate_query
3.0
CRAP 3.0
« Cellucidate/Request.pm ↑ Summary Cellucidate/Plot.pm »
1 package Bio::Cellucidate::Base;
2  
3 7 ▶use Bio::Cellucidate;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use Bio::Cellucidate::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 our %CONTENT_TYPES = (
9 'XML' => 'application/xml',
10 'CSV' => 'text/csv',
11 'KA' => 'application/x-kappa',
12 'M' => 'text/x-matlab'
13 );
14  
15 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
16 0 my $class = shift;
17 0 my $self = bless({}, $class);
18 0 $self;
19 }
20  
21 26 ▶sub client {
Subroutine client: called CC=2 SCAR=6.9
Pod undocumented
22 26 my $self = shift;
23 26 ▶ $self->{_client} = Bio::Cellucidate::Request->new($Bio::Cellucidate::CONFIG) unless $self->{_client};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_client"} 5 21 26
24 26 $self->{_client};
25 }
26  
27 # $self->rest('GET', '/foos', 'xml');
28 22 ▶sub rest {
Subroutine rest: called CC=4 SCAR=14.0
Pod undocumented
29 22 my $self = shift;
30 22 my $method = shift;
31 22 my $url = shift;
32 22 ▶ my $format = shift || 'xml';
Condition50%1/2
shift() || 'xml'
l!l
022
MC/DC0%0/1
shift() || 'xml'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
33 22 ▶ my $body = shift || undef;
Condition100%2/2
shift() || undef
l!l
517
MC/DC100%1/1
shift() || undef
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
34 22 ▶ my $header = shift || {};
Condition50%1/2
shift() || {}
l!l
022
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
35  
36 22 $self->client->request($method, $url, $body, { %{$header}, %{$self->headers_for_rest($format)} });
37 }
38  
39 22 ▶sub headers_for_rest {
Subroutine headers_for_rest: called CC=2 SCAR=7.0
Pod undocumented
40 22 my $self = shift;
41 22 ▶ my $format = shift || 'xml';
Condition50%1/2
shift() || 'xml'
l!l
220
MC/DC0%0/1
shift() || 'xml'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
42
43 22 my $header = HTTP::Headers->new;
44 22 $header->authorization_basic($Bio::Cellucidate::AUTH->{login}, $Bio::Cellucidate::AUTH->{api_key});
45 return { 'Authorization'=> $header->{authorization},
46 'Content-Type' => $CONTENT_TYPES{'XML'},
47 22 'Accept' => $CONTENT_TYPES{uc($format)} };
48 }
49  
50 0 ▶sub content_type_for_format {
Subroutine content_type_for_format: not called CC=1 SCAR=6.9
Pod undocumented
51 0 my $self = shift;
52 0 my $format = shift;
53 0 $CONTENT_TYPES[$format];
54 }
55  
56 # find({ name => foo }, 'xml')
57 9 ▶sub find {
Subroutine find: called CC=1 SCAR=0.0
Pod undocumented
58 9 my $self = shift;
59 9 my $args = $self->args(shift);
60 9 my $format = shift;
61 9 my $query = $self->formulate_query($args);
62 9 $self->rest('GET', $self->route . "/$query", $format)->processResponseAsArray($self->element);
63 }
64  
65 7 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
66 7 my $self = shift;
67 7 my $id = shift;
68 7 my $format = shift;
69 7 $self->rest('GET', $self->route . "/" . $id, $format)->processResponse;
70 }
71  
72 2 ▶sub update {
Subroutine update: called CC=1 SCAR=0.0
Pod undocumented
73 2 my $self = shift;
74 2 my $id = shift;
75 2 my $data = $self->args(shift);
76 2 my $format = shift;
77  
78 2 $self->rest('PUT', $self->route . "/" . $id, $format, XMLout($data, RootName => $self->element, NoAttr => 1))->processResponse;
79 }
80  
81 3 ▶sub create {
Subroutine create: called CC=1 SCAR=0.0
Pod undocumented
82 3 my $self = shift;
83 3 my $data = $self->args(shift);
84 3 my $format = shift;
85 3 $self->rest('POST', $self->route, $format, XMLout($data, RootName => $self->element, NoAttr => 1))->processResponse;
86 }
87  
88 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod undocumented
89 0 die "Unimplemented!";
90 }
91  
92 0 ▶sub route {
Subroutine route: not called CC=1 SCAR=6.9
Pod undocumented
93 0 die "Override in subclass";
94 }
95  
96 0 ▶sub element {
Subroutine element: not called CC=1 SCAR=6.9
Pod undocumented
97 0 die "Override in subclass";
98 }
99  
100 28 ▶sub args {
Subroutine args: called CC=5 SCAR=19.6
Pod undocumented
101 28 my $package = $_[0];
102 28 my $args = {};
103 28 ▶ if (ref $_[0] eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 28 28
elsif (scalar @_ and scalar @_ % 2 == 0) { } 28 0 28
104 0 $args = @_;
105 ▶ } elsif (scalar @_ && scalar @_ % 2 == 0) {
Condition33%1/3
scalar @_ and scalar @_ % 2 == 0
!ll&&!rl&&r
0028
MC/DC0%0/2
scalar @_ and scalar @_ % 2 == 0
scalar @_ scalar @_ % 2 == 0
Truth table33%1/3
A and B
A= scalar @_B= scalar @_ % 2 == 0
ABresult
0X0
100
111
106 28 $args = { @_ };
107 }
108 28 ▶ return $args->{$package} if $package;
Branch: 1 branch
BranchTrueFalseTotal
if $package 28 0 28
109 0 $args;
110 }
111  
112 12 ▶sub formulate_query {
Subroutine formulate_query: called CC=3 SCAR=11.0
Pod undocumented
113 12 my $args = args(@_);
114 12 my $query = '';
115 12 foreach my $key (keys %{$args}) {
116 9 ▶ $query = '?' if $query eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $query eq "" 6 3 9
117 9 $query .= "$key=" . $args->{$key} . "&";
118 }
119 12 $query;
120 }
121  
122 7 1;
« Cellucidate/Request.pm ↑ Summary Cellucidate/Plot.pm »