Skip to content

Commit

Permalink
Fix marklogic-community#638 Avoid duplication in get-modules-file xdm…
Browse files Browse the repository at this point in the history
…p:unquote calls.
  • Loading branch information
reecedunn67 committed Jul 27, 2016
1 parent 432a1b2 commit 36f5371
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/test/test-helper.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ declare function helper:get-modules-file($file as xs:string) {
};

declare function helper:get-modules-file($file as xs:string, $format as xs:string?) {
if (xdmp:modules-database() eq 0) then
let $doc :=
let $doc :=
if (xdmp:modules-database() eq 0) then
xdmp:document-get(
helper:build-uri(xdmp:modules-root(), $file),
if (fn:exists($format)) then
Expand All @@ -129,28 +129,23 @@ declare function helper:get-modules-file($file as xs:string, $format as xs:strin
</options>
else
())
return
else
xdmp:eval(
'declare variable $file as xs:string external; fn:doc($file)',
(xs:QName('file'), $file),
<options xmlns="xdmp:eval">
<database>{xdmp:modules-database()}</database>
</options>)
return
if ($doc/*) then
$doc
else
try {
xdmp:unquote($doc)
xdmp:unquote($doc) (: TODO WTF? :)
}
catch($ex) {$doc}
else
let $doc := xdmp:eval(
'declare variable $file as xs:string external; fn:doc($file)',
(xs:QName('file'), $file),
<options xmlns="xdmp:eval">
<database>{xdmp:modules-database()}</database>
</options>)
return
if ($doc/*) then
catch($ex) {
$doc
else
try {
xdmp:unquote($doc) (: TODO WTF? :)
}
catch($ex) {
$doc
}
}
};

(:~
Expand Down

0 comments on commit 36f5371

Please sign in to comment.