Jump to content
Wiki Home
EPrints Home
Bazaar
Files
Main menu
Main menu
move to sidebar
hide
Navigation
Front Page
EPrints 3 Manual
EPrints Training Course
EPrints Glossary
Installing EPrints
How-to Configure EPrints
EPrints 3.2+ API
EPrints 3 Reference
EPrints Plugins
Wiki
All categories
Recent changes
Main Page
Help
EPrints Documentation
Search
Search
Appearance
Log in
Request account
Personal tools
Log in
Request account
Pages for logged out editors
learn more
Contributions
Talk
Editing
Contribute: Plugins/ExportPluginsList
(section)
Page
Discussion
British English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
= In More Detail = The above code is very similar to the HelloExport.pm file in [[Contribute:_Plugins/ExportPluginsHello| the previous tutorial]] so only the points where it deviates significantly from that file will be discussed below. == Housekeeping == The package name has been changed to reflect the filename. <pre> package EPrints::Plugin::Export::MyPlugins::HelloList; </pre> == Constructor == Make sure you give each plugin a unique name. <pre> $self->{name} = 'Hello, List!'; </pre> == Dealing With Lists == In this example the output_list method is overridden in the export plugin to provide column headers. The original method just concatenates the output from the output_dataobj subroutine called on every DataObj in the list. Note that the method is not provided with a bare array of DataObjs, but a List object is provided within the opts hash. To get an array of DataObjs to loop over you must then call that List object's get_record method. == Filehandles == The command line export tool provides the output list method with a filehandle for output in the opts hash, while the [http://en.wikipedia.org/wiki/Common_Gateway_Interface CGI] export uses a value returned from the method. You must deal with the filehandle or you will get no output from the command line tool. In most cases this won't matter, but it is good practice to deal with it. The best way to handle output is to check if a filehandle has been provided every time something needs to be output. If a filehandle is provided we print to it, otherwise we save the output for later. At the end of the method we either return undef if a filehandle was provided or we return the saved output otherwise. <pre> sub output_list { my ($plugin, %opts) = @_; my $r = []; my $header = "ID\tTitle\n\n"; if (defined $opts{fh}) { print {$opts{fh}} $header; } else { push @{$r}, $header; } foreach my $dataobj ($opts{list}->get_records) { my $part = $plugin->output_dataobj($dataobj, %opts); if (defined $opts{fh}) { print {$opts{fh}} $part; } else { push @{$r}, $part; } } if (defined $opts{fh}) { return undef; } return join('', @{$r}); } </pre>
Summary:
Please note that all contributions to EPrints Documentation may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
EPrints Documentation:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)