From bec563228071328557332a63ecf2259d052e08f5 Mon Sep 17 00:00:00 2001
From: Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>
Date: Fri, 26 May 2017 18:42:44 +0200
Subject: [PATCH] Bug 7317: Implement generic optional capability system.

* Koha/Illrequest.pm (_backend_capability): New method.
---
 Koha/Illrequest.pm | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm
index 6677fcde03..50906b89fa 100644
--- a/Koha/Illrequest.pm
+++ b/Koha/Illrequest.pm
@@ -28,6 +28,7 @@ use Koha::Illrequest;
 use Koha::Illrequestattributes;
 use Koha::Patron;
 use Mail::Sendmail;
+use Try::Tiny;
 
 use base qw(Koha::Object);
 
@@ -157,6 +158,31 @@ sub _backend {
     return $self->{_my_backend};
 }
 
+=head3 _backend_capability
+
+    my $backend_capability_result = $self->_backend_capability($name, $args);
+
+This is a helper method to invoke optional capabilities in the backend.  If
+the capability named by $name is not supported, return 0, else invoke it,
+passing $args along with the invocation, and return its return value.
+
+=cut
+
+sub _backend_capability {
+    my ( $self, $name, $args ) = @_;
+    my $capability = 0;
+    try {
+        $capability = $self->_backend->capabilities($name);
+    } catch {
+        return 0;
+    };
+    if ( $capability ) {
+        return $capability($args);
+    } else {
+        return 0;
+    }
+}
+
 =head3 _config
 
     my $config = $abstract->_config($config);
-- 
2.11.0