NAME
SPOPS::Export - Export SPOPS objects to various formats
SYNOPSIS
use SPOPS::Export;
# Export to internal SPOPS format
my $exporter = SPOPS::Export->new( 'object',
{ object_class => 'My::Object' });
# Export all objects
print $exporter->run;
# Export only certain objects
$exporter->where( "user_id = 5" );
print $exporter->run;
$exporter->where( "last_name = ?" );
$exporter->value( [ "O'Reilly" ] );
print $exporter->run;
my $exporter2 = SPOPS::Export->new( 'xml',
{ object_class => 'My::Object' } );
# Export all objects
print $exporter2->run;
# Export only certain objects
$exporter2->where( "user_id = 5" );
print $exporter2->run;
$exporter2->where( "last_name = ?" );
$exporter2->value( [ "O'Reilly" ] );
print $exporter2->run;
DESCRIPTION
This is a simple module to export SPOPS objects into a portable format. The format depends on the type of exporting you are doing. Currently we support five formats, each of which has a unique identifier (in parens) that you pass to the new()
method:
SPOPS::Export::Object (object) An internal format based on serialized perl.
SPOPS::Export::XML (xml) Basic XML
SPOPS::Export::Perl (perl) Standard serialized Perl format using Data::Dumper.
SPOPS::Export::SQL (sql) A series of SQL statements, one for each record.
SPOPS::Export::DBI::Data (dbdata) Almost exactly like 'object' but it can be put directly into a DBI table without using objects.
PROPERTIES
You can set the following properties in the exporter object. Only one is mandatory.
object_class ($)
Class of the object for which you want to export the data. This should already be created via the normal means (see SPOPS::Initialize).
include_id (bool) (optional)
Whether to include the ID field its values in the exported data.
Default: false
skip_fields (\@) (optional)
Fields for which you do not want to include data.
Default: none
where ($) (optional)
A WHERE clause (or whatever the datasource supports) to export only certain data.
value (\@) (optional)
If you use placeholders in the where
property, replace them with values here.
METHODS
new( $export_type, \%params )
Create a new instance of an exporter. Since this is a factory class, we use $export_type
to determine the class used to create the exporter object. (The export types and classes are listed above.)
run()
Runs the configured export, returning a string with the exported data.
SUBCLASS METHODS
If you want to write your own exporter, you just need to create a class with the following methods. (Technically, all are optional, but you will not get too far if you do not implement at least create_record()
.)
Also: if you are writing your own exporter, be sure to look at the add_type()
method defined above.
initialize( \%params )
Perform any necessary initialization for an instance of your exporter object. Return the object.
create_header( \@object_fields )
Return a string with the export header.
create_record( $object, \@object_fields )
Return a string representing the object in the export format you are implementing.
create_footer()
Return a string with the export footer.
BUGS
None known.
TO DO
Nothing known.
SEE ALSO
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>