Difference between revisions of "Contribute: Plugins/ExportPluginsList"

From EPrints Documentation
Jump to: navigation, search
m (HelloList.pm)
(Export Plugin Tutorial 2: Hello, Lists: Copied code down.)
Line 2: Line 2:
  
 
== HelloList.pm ==
 
== HelloList.pm ==
 +
<pre>
 +
package EPrints::Plugin::Export::Foo::HelloList;
 +
 +
@ISA = ("EPrints::Plugin::Export");
 +
 +
use strict;
 +
 +
sub new
 +
{
 +
        my ($class, %opts) = @_;
 +
 +
        my $self = $class->SUPER::new(%opts);
 +
 +
        $self->{name} = "Hello, List!";
 +
        $self->{accept} = [ 'dataobj/eprint', 'list/eprint' ];
 +
        $self->{visible} = "all";
 +
        $self->{suffix} = ".txt";
 +
        $self->{mimetype} = "text/plain; charset=utf-8";
 +
 +
        return $self;
 +
}
 +
 +
sub output_dataobj
 +
{
 +
        my ($plugin, $dataobj) = @_;
 +
 +
        return $dataobj->get_id()."\t".$dataobj->get_value("title")."\n";
 +
}
 +
 +
sub output_list
 +
{
 +
        my ($plugin, %opts) = @_;
 +
 +
        my $output = "";
 +
 +
        $output .= "ID\tTitle\n\n";
 +
 +
        foreach my $dataobj ($opts{"list"}->get_records)
 +
        {
 +
                $output .= $plugin->output_dataobj($dataobj, %opts);
 +
        }
 +
 +
        return $output;
 +
}
 +
 +
1;
 +
</pre>
 +
 +
== In More Detail ==
 
<pre>
 
<pre>
 
package EPrints::Plugin::Export::Foo::HelloList;
 
package EPrints::Plugin::Export::Foo::HelloList;

Revision as of 13:38, 9 August 2007

Export Plugin Tutorial 2: Hello, Lists

HelloList.pm

package EPrints::Plugin::Export::Foo::HelloList;

@ISA = ("EPrints::Plugin::Export");

use strict;

sub new
{
        my ($class, %opts) = @_;

        my $self = $class->SUPER::new(%opts);

        $self->{name} = "Hello, List!";
        $self->{accept} = [ 'dataobj/eprint', 'list/eprint' ];
        $self->{visible} = "all";
        $self->{suffix} = ".txt";
        $self->{mimetype} = "text/plain; charset=utf-8";

        return $self;
}

sub output_dataobj
{
        my ($plugin, $dataobj) = @_;

        return $dataobj->get_id()."\t".$dataobj->get_value("title")."\n";
}

sub output_list
{
        my ($plugin, %opts) = @_;

        my $output = "";

        $output .= "ID\tTitle\n\n";

        foreach my $dataobj ($opts{"list"}->get_records)
        {
                $output .= $plugin->output_dataobj($dataobj, %opts);
        }

        return $output;
}

1;

In More Detail

package EPrints::Plugin::Export::Foo::HelloList;

@ISA = ("EPrints::Plugin::Export");

use strict;

sub new
{
        my ($class, %opts) = @_;

        my $self = $class->SUPER::new(%opts);

        $self->{name} = "Hello, List!";
        $self->{accept} = [ 'dataobj/eprint', 'list/eprint' ];
        $self->{visible} = "all";
        $self->{suffix} = ".txt";
        $self->{mimetype} = "text/plain; charset=utf-8";

        return $self;
}

sub output_dataobj
{
        my ($plugin, $dataobj) = @_;

        return $dataobj->get_id()."\t".$dataobj->get_value("title")."\n";
}

sub output_list
{
        my ($plugin, %opts) = @_;

        my $output = "";

        $output .= "ID\tTitle\n\n";

        foreach my $dataobj ($opts{"list"}->get_records)
        {
                $output .= $plugin->output_dataobj($dataobj, %opts);
        }

        return $output;
}

1;