Difference between revisions of "Core API"

From EPrints Documentation
Jump to: navigation, search
(CGI Script)
Line 51: Line 51:
 
   
 
   
 
  $session->terminate();
 
  $session->terminate();
 +
 +
== Code in the EPrints Configuration Files ==
 +
 +
Such as eprint_render.pl or creating a new subroutine for render_single_value on a field.
 +
 +
These are always passed a $session so you don't need to create your own.
 +
 +
== Plugins ==
 +
 +
These are described in the section about plugins.

Revision as of 17:40, 11 January 2007

Template:Api

This is the bits which you will need to get started...

A connection to the EPrints system is represented by an instance of EPrints::Session. The session object links to

  • the configuration of the repository (only one per session object, even if the system itself has multiple repositories).
  • the database for the repository.
  • the language to output in.

And if a CGI script then also

  • the EPrints::DataObj::User object of the current user, if any.
  • the apache request.

If you're writing your own script then you'll need to start by asking for a Session object.

Command-line Script

#!/usr/bin/perl -w -I/opt/eprints3/perl-lib/

use EPrints;

use strict;

my $archive_id = $ARGV[0];
my $session = new EPrints::Session( 1, $archive_id );
exit( 1 ) unless( defined $session );
 
# do your stuff
 
$session->terminate;

The "1" passed to Session tells it that we're a normal script and not a CGI script.

The $archive_id value is taken from $ARGV[0] which is the first parameter on the commandline. You could hard-wire the value if you wanted.

The use of "-w" to produce warnings and "use strict" to prevent sloppy code is just good Perl-practice.

CGI Script

This is similar to a command line script but you don't need the path to perl and the archive_id is not needed as it will work that out from the web-request.

use EPrints;
use strict;
my $session = new EPrints::Session;
exit( 0 ) unless( defined $session );
# do some stuff
# Return a result to browser (usually an HTML page)

$session->terminate();

Code in the EPrints Configuration Files

Such as eprint_render.pl or creating a new subroutine for render_single_value on a field.

These are always passed a $session so you don't need to create your own.

Plugins

These are described in the section about plugins.