NAME

SPOPS::Import - Factory and parent for importing SPOPS objects

SYNOPSIS

my $importer = SPOPS::Import->new( 'object' );
$importer->object_class( 'My::Object' );
$importer->fields( [ 'name', 'title', 'average' ] );
$importer->data( [ [ 'Steve', 'Carpenter', '160' ],
                   [ 'Jim', 'Engineer', '178' ],
                   [ 'Mario', 'Center', '201' ] ]);
$importer->run;

DESCRIPTION

This class is a factory class for creating importer objects. It is also the parent class for the importer objects.

METHODS

I/O

read_file( $filename )

Reads a file from $filename, returning the content.

read_perl_file( $filename )

Reads a file from $filename, then does an eval on the content to get back a Perl data structure. (Normal string eval caveats apply.)

Returns the Perl data structure.

read_fh( $filehandle )

Reads all (or remaining) information from $filehandle, returning the content.

raw_data_from_file( $filename )

Reads $filename as a Perl data structure and does perliminary checks to ensure it can be used in an import.

raw_data_from_fh( $filehandle )

Reads $filehandle as a Perl data structure and does perliminary checks to ensure it can be used in an import.

Subclasses

Subclasses should override the following methods.

run()

Runs the import and returns an arrayref of status entries, one for each record it tried to import.

Each status entry is an arrayref formatted:

[ status (boolean), record, message ]

If the import for this record was successful, the first (0) entry will be true and the third (2) entry will be undefined.

If the import for this record failed, the first (0) entry will be undefined and the third (2) entry will contain an error message.

Whether the import succeeds or fails, the second entry will contain the record we tried to import. The record is an arrayref, and if you want to map the values to fields just ask the importer object for its fields:

my $field_name = $importer->fields->[1];
foreach my $item ( @{ $status } ) {
   print "Value of $field_name: $item->[1][1]\n";
}

BUGS

None known.

TO DO

Nothing known.

SEE ALSO

SPOPS::Import

SPOPS::Manual::ImportExport

Class::Accessor

Class::Factory

COPYRIGHT

Copyright (c) 2001-2002 intes.net, inc.. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHORS

Chris Winters <chris@cwinters.com>