| 1 | package Elive::Connection; | ||||||||||||||||||||||||||||
| 2 | 22 | ▶ | use warnings; use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 22 | our $VERSION = '1.36'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 22 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 22 | ▶ | use File::Spec::Unix; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 22 | ▶ | use HTML::Entities; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 22 | ▶ | use Scalar::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 22 | require SOAP::Lite; | |||||||||||||||||||||||||||
| 11 | 22 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 22 | ▶ | use URI::Escape qw{}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 22 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 22 | ▶ | use YAML::Syck; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 22 | ▶ | use parent qw{Class::Accessor Class::Data::Inheritable}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 22 | ▶ | use Elive; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 22 | ▶ | use Elive::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 NAME | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | Elive::Connection - Manage Elluminate Live SOAP connections. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | This is an abstract class for managing connections and related resources. | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | Most of the time, you'll be dealing with specific class instances; See L<Elive::Connection::SDK> L<Elive::Connection::API>. | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 22 | __PACKAGE__->mk_accessors( qw{_url user pass _soap debug type timeout} ); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head1 METHODS | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =cut | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =head2 connect | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | my $sdk_c1 = Elive::Connection->connect('http://someserver.com/test', | ||||||||||||||||||||||||||||
| 42 | 'user1', 'pass1', debug => 1, | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | my $url1 = $sdk_c1->url; # 'http://someserver.com/test' | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | my $sdk_c2 = Elive::Connection->connect('http://user2:pass2@someserver.com/test'); | ||||||||||||||||||||||||||||
| 48 | my $url2 = $sdk_c2->url; # 'http://someserver.com/test' | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Establishes a logical SOAP connection. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub connect { | ||||||||||||||||||||||||||||
| 55 | 0 | ▶ | my ($class, $url, $user, $pass, %opt) = @_; | ||||||||||||||||||||||||||
|
Subroutine
connect: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||
| 57 | # default connection - for backwards compatibility | ||||||||||||||||||||||||||||
| 58 | # | ||||||||||||||||||||||||||||
| 59 | 0 | require Elive::Connection::SDK; | |||||||||||||||||||||||||||
| 60 | 0 | return Elive::Connection::SDK->connect($url, $user => $pass, %opt); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub _connect { | ||||||||||||||||||||||||||||
| 64 | 5 | ▶ | my ($class, $url, $user, $pass, %opt) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_connect: called CC=17 SCAR=29.4
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 5 | ▶ | my $debug = $opt{debug}||0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$opt{'debug'} || 0
MC/DC0%0/1
$opt{'debug'} || 0
$opt{'debug'}
Truth table50%1/2
A
A= $opt{'debug'}
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 5 | $url =~ s{/$}{}x; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 5 | my $uri_obj = URI->new($url); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 5 | my $userinfo = $uri_obj->userinfo; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 5 | ▶ | if ($userinfo) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # | ||||||||||||||||||||||||||||
| 77 | # extract and remove any credentials from the url | ||||||||||||||||||||||||||||
| 78 | # | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 3 | my ($uri_user, $uri_pass) = split(':',$userinfo, 2); | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 3 | ▶ | if ($uri_user) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 3 | ▶ | if ($user && $user ne $uri_user) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$user and $user ne $uri_user
MC/DC0%0/2
$user and $user ne $uri_user
$user
$user ne $uri_user
Truth table33%1/3
A and B
A= $userB= $user ne $uri_user
| |||||||||||||||||||||||||||||
| 84 | 0 | carp 'ignoring user in URI scheme - overridden'; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||||||||
| 87 | 3 | $user = URI::Escape::uri_unescape($uri_user); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 3 | ▶ | if ($uri_pass) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 3 | ▶ | if ($pass && $pass ne $uri_pass) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pass and $pass ne $uri_pass
MC/DC0%0/2
$pass and $pass ne $uri_pass
$pass
$pass ne $uri_pass
Truth table33%1/3
A and B
A= $passB= $pass ne $uri_pass
| |||||||||||||||||||||||||||||
| 93 | 0 | carp 'ignoring pass in URI scheme - overridden'; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | else { | ||||||||||||||||||||||||||||
| 96 | 3 | $pass = URI::Escape::uri_unescape($uri_pass); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 5 | my $uri_path = $uri_obj->path; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 5 | ▶ | $pass = '' unless defined $pass; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 5 | my @path = File::Spec::Unix->splitdir($uri_path); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 5 | ▶ | shift (@path) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@path and not $path[0]
MC/DC50%1/2
@path and not $path[0]
@path
not $path[0]
Truth table66%2/3
A and not(B)
A= @pathB= not $path[0]
| |||||||||||||||||||||||||||||
| 108 | if (@path && !$path[0]); | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 5 | ▶ | pop (@path) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@path and $path[-1] eq "webservice.event"
MC/DC50%1/2
@path and $path[-1] eq "webservice.event"
@path
$path[-1] eq "webservice.event"
Truth table66%2/3
A and B
A= @pathB= $path[-1] eq "webservice.event"
| |||||||||||||||||||||||||||||
| 111 | if (@path && $path[-1] eq 'webservice.event'); | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | # | ||||||||||||||||||||||||||||
| 114 | # normalise the connection url by removing suffixes. The following | ||||||||||||||||||||||||||||
| 115 | # all reduce to http://mysite/myinst: | ||||||||||||||||||||||||||||
| 116 | # -- http://mysite/myinst/webservice.event | ||||||||||||||||||||||||||||
| 117 | # -- http://mysite/myinst/v2 | ||||||||||||||||||||||||||||
| 118 | # -- http://mysite/myinst/v2/webservice.event | ||||||||||||||||||||||||||||
| 119 | # -- http://mysite/myinst/default | ||||||||||||||||||||||||||||
| 120 | # -- http://mysite/myinst/default/webservice.event | ||||||||||||||||||||||||||||
| 121 | # | ||||||||||||||||||||||||||||
| 122 | # there's some ambiguity, an instance named v1 ... v9 will cause trouble! | ||||||||||||||||||||||||||||
| 123 | # | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 5 | ▶ | pop(@path) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@path and $path[-1] =~ /^v(\d+)$/
MC/DC100%2/2
@path and $path[-1] =~ /^v(\d+)$/
@path
$path[-1] =~ /^v(\d+)$/
Truth table100%3/3
A and B
A= @pathB= $path[-1] =~ /^v(\d+)$/
| |||||||||||||||||||||||||||||
| 126 | if (@path && $path[-1] =~ m{^v(\d+)$}); | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 5 | $uri_obj->path(File::Spec::Unix->catdir(@path)); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 5 | my $soap_url = $uri_obj->as_string; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | # | ||||||||||||||||||||||||||||
| 133 | # remove any embedded credentials | ||||||||||||||||||||||||||||
| 134 | # | ||||||||||||||||||||||||||||
| 135 | 5 | ▶ | $soap_url =~ s{\Q${userinfo}\E\@}{} if $userinfo; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 5 | my $self = {}; | |||||||||||||||||||||||||||
| 138 | 5 | bless $self, $class; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 5 | $self->url($soap_url); | |||||||||||||||||||||||||||
| 141 | 5 | $self->user($user); | |||||||||||||||||||||||||||
| 142 | 5 | $self->pass($pass); | |||||||||||||||||||||||||||
| 143 | 5 | $self->debug($debug); | |||||||||||||||||||||||||||
| 144 | 5 | $self->timeout($opt{timeout}); | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 5 | return $self | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | sub _check_for_errors { | ||||||||||||||||||||||||||||
| 150 | 98 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
_check_for_errors: called CC=13 SCAR=39.0
| |||||||||||||||||||||||||||||
| 151 | 98 | my $som = shift; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 98 | ▶ | die "No response from server\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | unless $som; | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 98 | ▶ | die $som->fault->{ faultstring }."\n" if ($som->fault); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 98 | my $result = $som->result; | |||||||||||||||||||||||||||
| 159 | 98 | my @paramsout = $som->paramsout; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 98 | ▶ | warn YAML::Syck::Dump({result => $result, paramsout => \@paramsout}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | if ($class->debug); | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 98 | my @results = ($result, @paramsout); | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 98 | foreach my $result (@results) { | |||||||||||||||||||||||||||
| 167 | 196 | ▶ | next unless Scalar::Util::reftype($result); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # | ||||||||||||||||||||||||||||
| 170 | # Look for Elluminate-specific errors | ||||||||||||||||||||||||||||
| 171 | # | ||||||||||||||||||||||||||||
| 172 | 91 | ▶ | if ($result->{Code} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$result->{"Code"} and my $code = $result->{"Code"}{"Value"}
MC/DC0%0/2
$result->{"Code"} and my $code = $result->{"Code"}{"Value"}
$result->{"Code"}
my $code = $result->{"Code"}{"Value"}
Truth table33%1/3
A and B
A= $result->{"Code"}B= my $code = $result->{"Code"}{"Value"}
| |||||||||||||||||||||||||||||
| 173 | && (my $code = $result->{Code}{Value})) { | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | # | ||||||||||||||||||||||||||||
| 176 | # Elluminate error! | ||||||||||||||||||||||||||||
| 177 | # | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | my $reason = $result->{Reason}{Text}; | |||||||||||||||||||||||||||
| 180 | 0 | my @stack_trace; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | my $stack = $result->{Detail}{Stack}; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if ($stack && (my $trace = $stack->{Trace})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$stack and my $trace = $stack->{"Trace"}
MC/DC0%0/2
$stack and my $trace = $stack->{"Trace"}
$stack
my $trace = $stack->{"Trace"}
Truth table0%0/3
A and B
A= $stackB= my $trace = $stack->{"Trace"}
| |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | @stack_trace = (Elive::Util::_reftype($trace) eq 'ARRAY' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | ? @$trace | ||||||||||||||||||||||||||||
| 187 | : $trace); | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | my %seen; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | ▶ | my @error = grep {$_ && !$seen{$_}++} ($code, $reason, @stack_trace); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 0 | ▶ | my $msg = @error ? join(' ', @error) : YAML::Syck::Dump($result); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 0 | die "$msg\n"; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | =head2 check_command | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | my $command1 = Elive->check_command([qw{getUser listUser}]) | ||||||||||||||||||||||||||||
| 203 | my $command2 = Elive->check_command(deleteUser => 'd') | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | Find the first known command in the list. Raise an error if it's unknown; | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | See also: elive_lint_config. | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =cut | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | sub check_command { | ||||||||||||||||||||||||||||
| 212 | 200 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
check_command: called CC=13 SCAR=29.2
Pod
documented
| |||||||||||||||||||||||||||||
| 213 | 200 | my $commands = shift; | |||||||||||||||||||||||||||
| 214 | 200 | my $crud = shift; #create, read, update or delete | |||||||||||||||||||||||||||
| 215 | 200 | my $params = shift; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 200 | ▶ | if (Elive::Util::_reftype($commands) eq 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 0 | $commands = $commands->($crud, $params); | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 200 | ▶ | $commands = [$commands] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | unless Elive::Util::_reftype($commands) eq 'ARRAY'; | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 200 | my $usage = "usage: \$class->check_command(\$name[,'c'|'r'|'u'|'d'])"; | |||||||||||||||||||||||||||
| 225 | 200 | ▶ | die $usage unless @$commands && $commands->[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$commands and $commands->[0]
MC/DC0%0/2
@$commands and $commands->[0]
@$commands
$commands->[0]
Truth table33%1/3
A and B
A= @$commandsB= $commands->[0]
| |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 200 | my $known_commands = $class->known_commands; | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | die "no known commands for class: $class" | ||||||||||||||||||||||||||||
| 230 | 200 | ▶ | unless $known_commands && (keys %{$known_commands}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$known_commands and keys %{$known_commands;}
MC/DC0%0/2
$known_commands and keys %{$known_commands;}
$known_commands
keys %{$known_commands;}
Truth table33%1/3
A and B
A= $known_commandsB= keys %{$known_commands;}
| |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 200 | my ($command) = grep {exists $known_commands->{$_}} @$commands; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 200 | ▶ | croak "Unknown command(s): @{$commands}" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | unless $command; | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 200 | ▶ | if ($crud) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 98 | $crud = lc(substr($crud,0,1)); | |||||||||||||||||||||||||||
| 239 | 98 | ▶ | die $usage | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | unless $crud =~ m{^[c|r|u|d]$}xi; | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 98 | my $command_type = $known_commands->{$command}; | |||||||||||||||||||||||||||
| 243 | 98 | ▶ | die "misconfigured command: $command" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$command_type and $command_type =~ /^[c|r|u|d]+$/xi
MC/DC0%0/2
$command_type and $command_type =~ /^[c|r|u|d]+$/xi
$command_type
$command_type =~ /^[c|r|u|d]+$/xi
Truth table33%1/3
A and B
A= $command_typeB= $command_type =~ /^[c|r|u|d]+$/xi
| |||||||||||||||||||||||||||||
| 244 | unless $command_type && $command_type =~ m{^[c|r|u|d]+$}xi; | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 98 | ▶ | die "command $command. Type mismatch. Expected $crud, found $command_type" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | unless ($crud =~ m{[$command_type]}i); | ||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 200 | return $command; | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | =head2 known_commands | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | Returns an array of hash-value pairs for all Elluminate I<Live!> commands | ||||||||||||||||||||||||||||
| 256 | required by Elive. This list is cross-checked by the script elive_lint_config. | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | =cut | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | =head2 call | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | my $som = $self->call( $cmd, %params ); | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | Performs an Elluminate SOAP method call. Returns the response as a | ||||||||||||||||||||||||||||
| 265 | SOAP::SOM object. | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | =cut | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | sub call { | ||||||||||||||||||||||||||||
| 270 | 0 | ▶ | my ($self, $cmd, %params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
call: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 0 | $cmd = $self->check_command($cmd, undef, \%params); | |||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 0 | my @soap_params = $self->_preamble($cmd); | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 0 | foreach my $name (keys %params) { | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 0 | my $value = $params{$name}; | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | $value = SOAP::Data->type(string => Elive::Util::string($value)) | ||||||||||||||||||||||||||||
| 281 | unless (Scalar::Util::blessed($value) | ||||||||||||||||||||||||||||
| 282 | 0 | ▶ | && try {$value->isa('SOAP::Data')}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
Condition0%0/3
builtin::blessed($value) and &try(sub {
$value->isa("SOAP::Data");
}
)
MC/DC0%0/2
builtin::blessed($value) and &try(sub {
$value->isa("SOAP::Data");
}
)
builtin::blessed($value)
&try(sub {
$value->isa("SOAP::Data");
}
)
Truth table0%0/3
A and B
A= builtin::blessed($value)B= &try(sub {
$value->isa("SOAP::Data");
}
)
| |||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 0 | my $soap_param = $value->name($name); | |||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 0 | push (@soap_params, $soap_param); | |||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 0 | my $som = $self->soap->call( @soap_params ); | |||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 0 | return $som; | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | =head2 disconnect | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | Closes a connection. | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | =cut | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | sub disconnect { | ||||||||||||||||||||||||||||
| 301 | 32 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
disconnect: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 302 | 32 | return; | |||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | =head2 url | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | my $url1 = $connection1->url; | ||||||||||||||||||||||||||||
| 308 | my $url2 = $connection2->url; | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | Returns a restful url for the connection. | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | =cut | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | sub url { | ||||||||||||||||||||||||||||
| 315 | 338 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
url: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 316 | 338 | ▶ | $self->_url(@_) if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | 338 | return $self->_url; | |||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | sub DESTROY { | ||||||||||||||||||||||||||||
| 321 | 16 | ▶ | shift->disconnect; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 322 | 16 | return; | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | L<Elive::Connection::SDK> L<Elive::Connection::API> L<SOAP::Lite> | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | =cut | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 22 | 1; | |||||||||||||||||||||||||||