Skip to content

Instantly share code, notes, and snippets.

@jesusbagpuss
Created June 15, 2023 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesusbagpuss/66ee9937b0b57710bc5e775e0fbcf283 to your computer and use it in GitHub Desktop.
Save jesusbagpuss/66ee9937b0b57710bc5e775e0fbcf283 to your computer and use it in GitHub Desktop.
Test an EPrints Plugin
#!/usr/bin/perl -w
# Save this file in an EPrints installation - at [EPRINTS_ROOT]/bin/local/jlrs_plugin_test
#
# Run it with the following params:
# - archiveid
# - pluginid (e.g. Stats::Handler)
# - (optional) method_to_call
#
use FindBin;
use lib "$FindBin::Bin/../../perl_lib";
use strict;
use EPrints;
#repo and plugin are required.
my $repoid = $ARGV[0];
my $pluginid = $ARGV[1];
my $method = $ARGV[2];
if( !defined $repoid || !defined $pluginid ){
print STDERR "Please supply ARCHIVEID Plugin::Id\n";
print STDERR "\tplugin id should be in the form Screen::EPMC::Timescapes\n";
exit 1;
}
my $session = new EPrints::Session( 1, $repoid, 1 );
if( !defined $session )
{
print STDERR "Failed to load repository: $repoid\n";
exit 1;
}
my $plugin = $session->plugin( $pluginid );
if( !defined $plugin ){
print STDERR "Couldn't find $pluginid\n";
$session->terminate;
exit 1;
}
if( $plugin->broken ){
print STDERR "Plugin $pluginid could not run because:\n";
print STDERR $plugin->error_message."\n";
$session->terminate;
exit 1;
}
print "Plugin $pluginid seems to be OK...\n";
if( defined $method )
{
print "Calling method $method on $pluginid\n";
if( $plugin->can( $method ) )
{
print "$pluginid->$method result:\t", $plugin->$method, "\n";
}
else
{
print "Hmmm, $pluginid doesn't seem to be able to $method...!?\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment