eprintsug / DataCiteDoi

Registration of DOIs via DataCite
GNU General Public License v3.0
2 stars 5 forks source link

Excessive warning messages #41

Closed goetzk closed 5 years ago

goetzk commented 5 years ago

In 4766bfbc9a3c82e3e750ee6d05c85487b8a2f455 I added warnings in case the two SSL backends were not installed. Unfortunately it still triggers even if (for example) WWW::Curl is not wanted.

Use $c->{datacitedoi}{use_curl} to determine which backend is in use and only warn when appropriate.

goetzk commented 5 years ago

I'm testing a change which looks like this at the moment.

--- a/lib/plugins/EPrints/Plugin/Event/DataCiteEvent.pm
+++ b/lib/plugins/EPrints/Plugin/Event/DataCiteEvent.pm
@@ -8,11 +8,10 @@ package EPrints::Plugin::Event::DataCiteEvent;

 use EPrints::Plugin::Event;

-eval "use LWP; use HTTP::Headers::Util; 1";
-if ( $@ ) { print STDERR "Unable to import LWP or HTTP::Headers::Util.\n"; }
+# Silently import, we'll warn on failure once the repository is configured.
+eval "use LWP; use HTTP::Headers::Util";

-eval "use WWW::Curl::Easy; 1";
-if ( $@ ) { print STDERR "Unable to import WWW::Curl::Easy.\n"; }
+eval "use WWW::Curl::Easy";

 @ISA = qw( EPrints::Plugin::Event );
@@ -23,6 +22,15 @@ sub datacite_doi

                my $repository = $self->repository();

+if (defined $repository->get_conf( "datacitedoi", "get_curl")) {
+       # Try and import Curl.
+       if ( eval "use WWW::Curl::Easy" ) { print STDERR "Unable to import WWW::Curl::Easy.\n"; }
+} else {
+       # Fall back to LWP and rely in its library detection.
+       if ( eval "use LWP" ) { print STDERR "Unable to import LWP.\n"; }
+       if ( eval "use HTTP::Headers::Util" ) { print STDERR "Unable to import HTTP::Headers::Util.\n"; }
+}
+
                # Check object status first.... TODO: Make work for dataobj == document (just in case)
                my $shoulddoi = $repository->get_conf( "datacitedoi", "eprintstatus",  $dataobj->value( "eprint_status" ));
                #Check Doi Status
goetzk commented 5 years ago

Resolved with branch merge.