Subject: [PATCH v3 1/2] gnu: perl-xml-xpath: Wrap xpath command.

From: Bruno Victal <[email-masked]>
Date: Sat, 27 May 2023 19:11:28 +0100

* gnu/packages/xml.scm (perl-xml-xpath)[arguments]: Wrap xpath. Add test for
wrapped xpath.
[description]: Document xpath command presence.
---

Notable changes since v2:
* Wrap xpath minimally.
* Add a phase to check if the wrapped xpath works.
* Add missing test dependency.

 gnu/packages/xml.scm | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/xml.scm b/gnu/packages/xml.scm
index 2bc4f66c01..ec622cec63 100644
--- a/gnu/packages/xml.scm
+++ b/gnu/packages/xml.scm
@@ -33,6 +33,7 @@
 ;;; Copyright © 2021 Guillaume Le Vaillant <[email-masked]>
 ;;; Copyright © 2021 David Larsson <[email-masked]>
 ;;; Copyright © 2021 Matthew James Kraai <[email-masked]>
+;;; Copyright © 2023 Bruno Victal <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1044,6 +1045,28 @@ (define-public perl-xml-xpath
                (base32
                 "03yxj7w5a43ibbpiqsvb3lswj2b71dydsx4rs2fw0p8n0l3i3j8w"))))
     (build-system perl-build-system)
+    (arguments
+     (list
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'wrap 'wrap-xpath
+            (lambda _
+              (let ((xpath (string-append #$output "/bin/xpath"))
+                    (perl5lib
+                     (list #$@(map (lambda (i)
+                                     (file-append (this-package-input i)
+                                                  "/lib/perl5/site_perl"))
+                                   '("perl-xml-parser"))
+                           (string-append #$output
+                                          "/lib/perl5/site_perl/"
+                                          #$(package-version perl)))))
+                (wrap-program xpath
+                  `("PERL5LIB" ":" prefix ,perl5lib)))))
+          (add-after 'wrap-xpath 'check-wrap
+            (lambda* (#:key tests? #:allow-other-keys)
+              (when tests?
+                (unsetenv "PERL5LIB")
+                (invoke/quiet (string-append #$output "/bin/xpath"))))))))
     (native-inputs
      (list perl-path-tiny))
     (propagated-inputs
@@ -1053,7 +1076,7 @@ (define-public perl-xml-xpath
     (description
      "This module aims to comply exactly to the @url{XPath specification,
 https://www.w3.org/TR/xpath} and yet allow extensions to be added in
-the form of functions.")
+the form of functions.  It also provides the command @command{xpath}.")
     (license license:perl-license)))
 
 (define-public pugixml

base-commit: b96b82bcd4bc24529941ff74a91432481f1a71b5
-- 
2.39.2