Handling Dependencies

From EPrints Documentation
Jump to: navigation, search

This page outlines several methods to check dependancies on Bazaar package.

All Dependency checking is done with a packages EPMC screen, so you will need to configure a basic EPMC screen for your plugin.

Checking Perl Library Dependencies

The following block of code checks for perl libraries, in this case Digest::HMAC_SHA1.

If any of the dependancies are missing we can handle these later in render_messages.

This piece of code is designed to exist in the enable method of an EPMC screen.

 my @prereqs = qw/ Digest::HMAC_SHA1 /;
 my $evalstring;
 foreach my $l (@prereqs)
       $evalstring .= "use $l;\n";
 eval $evalstring;
 if (!$@)
      $self->SUPER::action_enable( $skip_reload );

This example is from the AmazonS3 plugin.

Checking Binary Dependencies

Ideally users should be able to specify the paths to binary executables in a config file and your config file should list the most "default" location.


 $c->{"exif_import"}->{"exif_path"} = '/usr/bin/exiftool';

The you can use the following code to check for the binary on the system.

 my $exiftool = $repo->get_repository->get_conf( "exif_import", "exif_path" );
  if (! (-e $exiftool) ) 
      #binary not found

Providing persistant helpful messages for users

A "render_messages" method can be used to provide useful messages to the user about how they need to configure their package, e.g. what dependencies they need.

This example comes from the exiftool import package.

 sub render_messages
       my( $self ) = @_;
       my $repo = $self->{repository};
       my $xml = $repo->xml;
       my $frag = $xml->create_document_fragment;
       my $exiftool = $repo->get_repository->get_conf( "exif_import", "exif_path" );
       if ( -e $exiftool ) {
       } else {
               my $msg = $xml->create_document_fragment;
               $msg->appendChild($xml->create_text_node('exiftool not found on your system. You need to install exiftool and/or configure this plugin with the location of exiftool.'));
               $frag->appendChild( $repo->render_message( 'error', $msg ) );
       return $frag;