| 1 | package WWW::SFDC::Role::CRUD; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Shared methods between partner and tooling APIs | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use 5.12.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '0.36'; # TRIAL VERSION | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use List::NSect 'spart'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Log::Log4perl ':easy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Method::Signatures; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use SOAP::Lite; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 2 | requires qw'_prepareSObjects'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | method _queryMore ($locator) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=4.1
Subroutine
_queryMore: not called CC=3 SCAR=20.7
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 22 | 0 | return $self->_call( | |||||||||||||||||||||||||||
| 23 | 'queryMore', | ||||||||||||||||||||||||||||
| 24 | SOAP::Data->name(queryLocator => $locator), | ||||||||||||||||||||||||||||
| 25 | )->result; | ||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # Extract the results from a $request. This handles the case | ||||||||||||||||||||||||||||
| 29 | # where there is only one result, as well as 0 or more than 1. | ||||||||||||||||||||||||||||
| 30 | # They require different handling because in the 1 case, you | ||||||||||||||||||||||||||||
| 31 | # can't handle it as an array | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | method _getQueryResults ($request) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=4.1
Subroutine
_getQueryResults: not called CC=4 SCAR=26.9
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 33 | 0 | TRACE Dumper $request; | |||||||||||||||||||||||||||
| 34 | return ref $request->{records} eq 'ARRAY' | ||||||||||||||||||||||||||||
| 35 | 0 | ? map {$self->_cleanUpSObject($_)} @{$request->{records}} | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | : ( $self->_cleanUpSObject($request->{records}) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # Unbless an SObject, and de-duplicate the ID field - SFDC | ||||||||||||||||||||||||||||
| 40 | # duplicates the ID, which is interpreted as an arrayref! | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | method _cleanUpSObject ($obj) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=4.1
Subroutine
_cleanUpSObject: not called CC=12 SCAR=49.1
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return () unless $obj; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | my %copy = %$obj; # strip the class from $obj | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | $copy{Id} = $copy{Id}->[0] if $copy{Id} and ref $copy{Id} eq "ARRAY"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$copy{"Id"} and ref $copy{"Id"} eq "ARRAY"
MC/DC0%0/2
$copy{"Id"} and ref $copy{"Id"} eq "ARRAY"
$copy{"Id"}
ref $copy{"Id"} eq "ARRAY"
Truth table0%0/3
A and B
A= $copy{"Id"}B= ref $copy{"Id"} eq "ARRAY"
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | delete $copy{Id} unless $copy{Id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | while (my ($key, $entry) = each %copy) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | next unless blessed $entry; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if (blessed $entry eq 'sObject') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 50 | 0 | $copy{$key} = $self->_cleanUpSObject($entry); | |||||||||||||||||||||||||||
| 51 | } elsif (blessed $entry eq 'QueryResult') { | ||||||||||||||||||||||||||||
| 52 | $entry = [ | ||||||||||||||||||||||||||||
| 53 | ref $entry->{records} eq 'ARRAY' | ||||||||||||||||||||||||||||
| 54 | 0 | ? map {$self->_cleanUpSObject($_)} @{$entry->{records}} | |||||||||||||||||||||||||||
| 55 | : $self->_cleanUpSObject($entry->{records}) | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | return \%copy; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # Chain together calls to _queryMore() and handle the results. | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | method _completeQuery ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.0
Subroutine
_completeQuery: not called CC=7 SCAR=39.0
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | :$query!, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | :$method!, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | :$callback = sub {state @results; push @results, @_; return @results} | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 68 | ) { | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | INFO "Executing SOQL query: $query"; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | my $result = $self->_call( | |||||||||||||||||||||||||||
| 73 | $method, | ||||||||||||||||||||||||||||
| 74 | SOAP::Data->name(queryString => $query) | ||||||||||||||||||||||||||||
| 75 | )->result; | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | my @results = $callback->($self->_getQueryResults($result)); | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | until ($result->{done} eq 'true') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | $self->_sleep(); | |||||||||||||||||||||||||||
| 80 | 0 | $result = $self->_queryMore($result->{queryLocator}); | |||||||||||||||||||||||||||
| 81 | 0 | @results = $callback->($self->_getQueryResults($result)); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | return @results; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | method query ($params) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=4.1
Subroutine
query: not called CC=4 SCAR=26.2
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | return $self->_completeQuery( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | ref $params | ||||||||||||||||||||||||||||
| 90 | ? %$params | ||||||||||||||||||||||||||||
| 91 | : (query => $params), | ||||||||||||||||||||||||||||
| 92 | method => 'query' | ||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | method queryAll ($params) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=4.1
Subroutine
queryAll: not called CC=4 SCAR=26.2
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | return $self->_completeQuery( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | ref $params | ||||||||||||||||||||||||||||
| 99 | ? %$params | ||||||||||||||||||||||||||||
| 100 | : (query => $params), | ||||||||||||||||||||||||||||
| 101 | method => 'queryAll' | ||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | method create (@_) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
create: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||
| 108 | return map { | ||||||||||||||||||||||||||||
| 109 | 0 | @{$self->_call( | |||||||||||||||||||||||||||
| 110 | 'create', | ||||||||||||||||||||||||||||
| 111 | $self->_prepareSObjects(@$_) | ||||||||||||||||||||||||||||
| 112 | )->results}; | ||||||||||||||||||||||||||||
| 113 | } spart 200, @_; | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | method update (@_) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
update: not called CC=1 SCAR=3.1
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | TRACE "Objects for update" => \@_; | |||||||||||||||||||||||||||
| 120 | 0 | INFO "Updating objects"; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | return @{$self->_call( | |||||||||||||||||||||||||||
| 123 | 'update', | ||||||||||||||||||||||||||||
| 124 | $self->_prepareSObjects(@_) | ||||||||||||||||||||||||||||
| 125 | )->results}; | ||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | method delete (@_) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
delete: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | DEBUG "IDs for deletion" => \@_; | |||||||||||||||||||||||||||
| 132 | 0 | INFO "Deleting objects"; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | return @{$self->_call( | |||||||||||||||||||||||||||
| 135 | 'delete', | ||||||||||||||||||||||||||||
| 136 | 0 | map {SOAP::Data->name('ids' => $_)} @_ | |||||||||||||||||||||||||||
| 137 | )->results}; | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | method undelete (@_) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
undelete: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | DEBUG "IDs for undelete" => \@_; | |||||||||||||||||||||||||||
| 144 | 0 | INFO "Deleting objects"; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | return @{$self->_call( | |||||||||||||||||||||||||||
| 147 | 'undelete', | ||||||||||||||||||||||||||||
| 148 | 0 | map {SOAP::Data->name('ids' => $_)} @_ | |||||||||||||||||||||||||||
| 149 | )->results}; | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | method retrieve (@_) { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
retrieve: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | DEBUG "IDs for retrieve" => \@_; | |||||||||||||||||||||||||||
| 156 | 0 | INFO "Retrieving objects"; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | return @{$self->_call( | |||||||||||||||||||||||||||
| 159 | 'retrieve', | ||||||||||||||||||||||||||||
| 160 | 0 | map {SOAP::Data->name('ids' => $_)} @_ | |||||||||||||||||||||||||||
| 161 | )->results}; | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 2 | 1; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | __END__ | ||||||||||||||||||||||||||||