SFDC/Metadata.pm

filter: Statementstmt 40.3% 46 / 114 Branchbran 0.0% 0 / 42 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 65.3% 17 / 26 Podpod n/a totaltotal 34.6% 63 / 182 CC 23 SCAR 23.3
CC
23
Cov
29%
deployMetadata
23.2
_checkRetrieval
22.9
_checkDeployment
15.2
CRAP 10.2
« SFDC.pm ↑ Summary SFDC/Tooling.pm »
1 package WWW::SFDC::Metadata;
2 # ABSTRACT: Interface to the Salesforce.com Metadata API
3  
4 1 ▶use 5.12.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.36'; # TRIAL VERSION
9  
10 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Log::Log4perl ':easy';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use SOAP::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use WWW::SFDC::Metadata::DeployResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 with "WWW::SFDC::Role::SessionConsumer";
19  
20 1 has 'uri',
21 is => 'ro',
22 default => "http://soap.sforce.com/2006/04/metadata";
23  
24 0 ▶sub _extractURL {
Subroutine _extractURL: not called CC=1 SCAR=6.9
25 0 return $_[1]->{metadataServerUrl};
26 }
27  
28  
29 0 ▶method listMetadata {
Subroutine BEGIN: called CC=1 SCAR=2.6
Subroutine listMetadata: not called CC=4 SCAR=26.9
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 0 0
30  
31 0 INFO "Listing Metadata...\t";
32  
33 0 my @result;
34 0 my @queryData = map {SOAP::Data->new(name => "queries", value => $_)} @_;
35  
36 # listMetadata can only handle 3 requests at a time, so we chunk them.
37 0 ▶ while (my @items = splice @queryData, 0, 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@items) = splice(@queryData, 0, 3)) 0 0 0
38 0 push @result, $$_{fileName} for @{$self->_call('listMetadata', @items)->results};
39 }
40  
41 0 return @result;
42 }
43  
44  
45 # Sets up an asynchronous metadata retrieval request and
46 # returns just the id, for checking later. Accepts a manifest.
47  
48 0 ▶method _startRetrieval ($manifest) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine _startRetrieval: not called CC=3 SCAR=22.0
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
if scalar @_ > 1 0 0 0
49 0 INFO "Starting retrieval";
50  
51 # These maps basically preserve the structure passed in,
52 # translating it to salesforce's special package.xml structure.
53 my @queryData = map {
54 0 SOAP::Data->name (
55 types => \SOAP::Data->value(
56 0 map {SOAP::Data->name(members => $_) } @{ $$manifest{$_} },
57 SOAP::Data->name(name => $_ )
58 )
59 )
60 } keys %$manifest;
61  
62  
63 return $self->_call(
64 'retrieve',
65 SOAP::Data->name(
66 retrieveRequest => {
67 # a lower value than 31 means no status is retrieved, causing an error.
68 apiVersion => $self->session->apiVersion(),
69 unpackaged => \SOAP::Data->value(@queryData)
70 })
71 0 )->result->{id};
72  
73 }
74  
75 # Uses the id to request a status update from SFDC, and returns
76 # undef unless there's something to give back, in which case it
77 # returns the base64 encoded zip file from the response.
78  
79 0 ▶method _checkRetrieval ($id) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine _checkRetrieval: not called CC=5 SCAR=31.3
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
if scalar @_ > 1 0 0 0
80  
81 0 my $result = $self->_call(
82 'checkRetrieveStatus',
83 SOAP::Data->name("asyncProcessId" => $id)
84 )->result;
85  
86 0 INFO "Status:" . $$result{status};
87  
88 0 ▶ return $result->{zipFile} if $$result{status} eq "Succeeded";
Branch: 1 branch
BranchTrueFalseTotal
if $result->{"status"} eq "Succeeded" 0 0 0
89 0 ▶ return if $$result{status} =~ /Pending|InProgress/;
Branch: 1 branch
BranchTrueFalseTotal
if $result->{"status"} =~ /Pending|InProgress/u 0 0 0
90 0 LOGDIE "Check Retrieve had an unexpected result: ".$$result{message};
91 }
92  
93  
94 0 ▶method retrieveMetadata ($manifest) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine retrieveMetadata: not called CC=4 SCAR=27.1
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
if scalar @_ > 1 0 0 0
95  
96 0 my $requestId = $self->_startRetrieval($manifest);
97 0 my $result;
98  
99 0 ▶ do { $self->_sleep() } until $result = $self->_checkRetrieval($requestId);
Branch: 1 branch
BranchTrueFalseTotal
$result = $self->_checkRetrieval($requestId) or do { do { $self->_sleep } } 0 0 0
100  
101 0 return $result;
102  
103 }
104  
105  
106 #Check up on an async deployment request. Returns 1 when complete.
107 0 ▶method _checkDeployment ($id, $previous?) {
Subroutine BEGIN: called CC=1 SCAR=4.4
Subroutine _checkDeployment: not called CC=4 SCAR=27.2
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
if scalar @_ > 2 0 0 0
108  
109 0 my $callResult = $self->_call(
110 'checkDeployStatus',
111 SOAP::Data->name("id" => $id),
112 SOAP::Data->name("includeDetails" => "true")
113 )->result;
114  
115 0 my $result = WWW::SFDC::Metadata::DeployResult->new(
116 result => $callResult
117 );
118  
119 0 ▶ if (scalar (my @errors = (
Branch: 1 branch
BranchTrueFalseTotal
if (scalar(my(@errors) = ($result->componentFailuresSince($previous), $result->testFailuresSince($previous)))) 0 0 0
120 $result->componentFailuresSince($previous),
121 $result->testFailuresSince($previous)
122 ))) {
123 0 WARN Dumper \@errors;
124 }
125  
126 0 return $result
127 }
128  
129 0 ▶method deployMetadata ($zip, $deployOptions?) {
Subroutine BEGIN: called CC=1 SCAR=4.4
Subroutine deployMetadata: not called CC=5 SCAR=31.5
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
if scalar @_ > 2 0 0 0
130  
131 0 ▶ my $result = $self->_call(
Branch: 1 branch
BranchTrueFalseTotal
$deployOptions ? : 0 0 0
132 'deploy',
133 SOAP::Data->name( zipfile => $zip),
134 (
135 $deployOptions
136 ? SOAP::Data->name(DeployOptions=>$deployOptions)
137 : ()
138 )
139 )->result;
140  
141 0 INFO "Deployment ID: $$result{id}";
142  
143 0 my $returnValue;
144  
145 #do..until guarantees that sleep() executes at least once.
146 $self->_sleep()
147 until (
148 0 ▶ $returnValue = $self->_checkDeployment($$result{id}, $returnValue)
Branch: 1 branch
BranchTrueFalseTotal
($returnValue = $self->_checkDeployment($result->{"id"}, $returnValue))->complete or do { $self->_sleep } 0 0 0
149 )->complete;
150  
151 0 return $returnValue;
152 }
153  
154  
155 0 ▶method deployRecentValidation ($id) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine deployRecentValidation: not called CC=3 SCAR=21.1
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
if scalar @_ > 1 0 0 0
156 0 chomp $id;
157  
158 0 return WWW::SFDC::Metadata::DeployResult->new(
159 result => $self->_call(
160 'deployRecentValidation',
161 SOAP::Data->name(validationID => $id)
162 )->result
163 );
164 }
165  
166  
167 0 ▶method describeMetadata {
Subroutine BEGIN: called CC=1 SCAR=2.6
Subroutine describeMetadata: not called CC=2 SCAR=12.4
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 0 0
168 0 return $self->_call(
169 'describeMetadata',
170 SOAP::Data->name(apiVersion => $self->session->apiVersion)
171 )->result;
172 }
173  
174 1 1;
175  
176 __END__
« SFDC.pm ↑ Summary SFDC/Tooling.pm »