blib/lib/Math/Matlab/Remote.pm

filter: Statementstmt 56.9% 33 / 58 Branchbran 40.0% 8 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 10 / 15 Podpod 100% 6 / 6 totaltotal 55.8% 57 / 102 CC 8 SCAR 17.6
CC
8
Cov
51%
execute
20.0
new
6.2
uri
2.0
CRAP 5.8
« blib/lib/Math/Matlab/Server.pm ↑ Summary blib/lib/Math/Matlab.pm »
1 package Math::Matlab::Remote;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION $URI $TIMEOUT $USER $PASS);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $VERSION = sprintf "%d.%03d", q$Revision: 1.6 $ =~ /: (\d+)\.(\d+)/;
8 }
9  
10 1 ▶use Math::Matlab;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use base qw( Math::Matlab );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use URI::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 ##----- assign defaults, unless already set externally -----
19 1 ▶$URI = '' unless defined $URI;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Math::Matlab::Remote::URI 0 1 1
20 1 ▶$TIMEOUT = 300 unless defined $TIMEOUT; ## default = 5 min
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Math::Matlab::Remote::TIMEOUT 1 0 1
21 1 ▶$USER = '' unless defined $USER;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Math::Matlab::Remote::USER 0 1 1
22 1 ▶$PASS = '' unless defined $PASS;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Math::Matlab::Remote::PASS 0 1 1
23  
24 ##----- Public Class Methods -----
25 1 ▶sub new {
Subroutine new: called CC=5 SCAR=18.2
Pod documented
26 1 my ($class, $href) = @_;
27 my $self = {
28 uri => defined($href->{uri}) ? $href->{uri} : $URI,
29 timeout => defined($href->{timeout}) ? $href->{timeout} : $TIMEOUT,
30 user => defined($href->{user}) ? $href->{user} : $USER,
31 1 ▶ pass => defined($href->{pass}) ? $href->{pass} : $PASS,
Branch: 4 branches
BranchTrueFalseTotal
defined $href->{'uri'} ? : 0 1 1
defined $href->{'timeout'} ? : 0 1 1
defined $href->{'user'} ? : 0 1 1
defined $href->{'pass'} ? : 0 1 1
32 err_msg => '',
33 result => ''
34 };
35  
36 1 bless $self, $class;
37 }
38  
39 ##----- Public Object Methods -----
40 0 ▶sub execute {
Subroutine execute: not called CC=4 SCAR=30.0
Pod documented
41 0 my ($self, $code, $rel_mwd) = @_;
42
43 ## set up the request
44 0 ▶ my %form = (
Condition0%0/2
$rel_mwd || ''
l!l
00
MC/DC0%0/1
$rel_mwd || ''
$rel_mwd
Truth table0%0/2
A
A= $rel_mwd
Aresult
11
00
45 'RAW_OUTPUT' => 1,
46 'CODE' => $code,
47 'REL_MWD' => $rel_mwd || ''
48 );
49 0 my $request = new HTTP::Request('POST' => $self->uri);
50 0 $request->content_type('application/x-www-form-urlencoded');
51 0 my $curl = new URI::URL('http:');
52 0 $curl->query_form( %form );
53 0 $request->content($curl->equery);
54 0 ▶ $request->authorization_basic($self->user, $self->pass) if $self->user;
Branch: 1 branch
BranchTrueFalseTotal
if $self->user 0 0 0
55  
56 ## set up the user agent
57 0 my $ua = new LWP::UserAgent;
58 0 $ua->agent( __PACKAGE__ . "/$VERSION " . $ua->agent);
59 0 $ua->timeout($self->timeout);
60  
61 ## do the request
62 0 my $response = $ua->request($request);
63
64 0 ▶ if ($response->is_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_error) { } 0 0 0
65 0 $self->err_msg( $response->status_line );
66 0 return 0;
67 } else {
68 0 $self->{'result'} = $response->content;
69 0 return 1;
70 }
71 }
72  
73 0 ▶sub uri { my $self = shift; return $self->_getset('uri', @_); }
Subroutine uri: not called CC=1 SCAR=6.9
Pod documented
74 0 ▶sub timeout { my $self = shift; return $self->_getset('timeout', @_); }
Subroutine timeout: not called CC=1 SCAR=6.9
Pod documented
75 0 ▶sub user { my $self = shift; return $self->_getset('user', @_); }
Subroutine user: not called CC=1 SCAR=6.9
Pod documented
76 0 ▶sub pass { my $self = shift; return $self->_getset('pass', @_); }
Subroutine pass: not called CC=1 SCAR=6.9
Pod documented
77  
78 1 1;
79 __END__
« blib/lib/Math/Matlab/Server.pm ↑ Summary blib/lib/Math/Matlab.pm »