Added "takelike" option.
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / XML.pm
index 2315b20..18b5c68 100644 (file)
@@ -1,11 +1,9 @@
 package SQL::Translator::Producer::XML;
 
 # -------------------------------------------------------------------
-# $Id: XML.pm,v 1.11 2003-07-31 20:48:23 dlc Exp $
+# $Id: XML.pm,v 1.16 2004-02-09 23:02:17 kycl4rk Exp $
 # -------------------------------------------------------------------
-# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
-#                    darren chamberlain <darren@cpan.org>,
-#                    Chris Mungall <cjm@fruitfly.org>
+# Copyright (C) 2002-4 SQLFairy Authors
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -22,143 +20,37 @@ package SQL::Translator::Producer::XML;
 # 02111-1307  USA
 # -------------------------------------------------------------------
 
-use strict;
-use vars qw[ $VERSION ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.11 $ =~ /(\d+)\.(\d+)/;
+=pod
 
-use IO::Scalar;
-use SQL::Translator::Utils qw(header_comment);
-use XML::Writer;
+=head1 NAME
 
-my $namespace = 'http://sqlfairy.sourceforge.net/sqlfairy.xml';
-my $name = 'sqlt';
+SQL::Translator::Producer::XML - Alias to XML::SQLFairy producer
 
-# -------------------------------------------------------------------
-sub produce {
-    my $translator = shift;
-    my $schema     = $translator->schema;
-    my $args       = $translator->producer_args;
-
-    my $io          = IO::Scalar->new;
-    my $xml         = XML::Writer->new(
-        OUTPUT      => $io,
-        NAMESPACES  => 1,
-        PREFIX_MAP  => { $namespace => $name },
-        DATA_MODE   => 1,
-        DATA_INDENT => 2,
-    );
-
-    $xml->xmlDecl('UTF-8');
-    $xml->comment(header_comment('', ''));
-    $xml->startTag([ $namespace => 'schema' ]);
-
-    for my $table ( $schema->get_tables ) {
-        my $table_name = $table->name or next;
-        $xml->startTag   ( [ $namespace => 'table' ] );
-        $xml->dataElement( [ $namespace => 'name'  ], $table_name );
-        $xml->dataElement( [ $namespace => 'order' ], $table->order );
-
-        #
-        # Fields
-        #
-        $xml->startTag( [ $namespace => 'fields' ] );
-        for my $field ( $table->get_fields ) {
-            $xml->startTag( [ $namespace => 'field' ] );
-
-            for my $method ( 
-                qw[ 
-                    name data_type default_value is_auto_increment 
-                    is_primary_key is_nullable is_foreign_key order size
-                ]
-            ) {
-                my $val = $field->$method || '';
-                $xml->dataElement( [ $namespace => $method ], $val )
-                    if ( defined $val || 
-                        ( !defined $val && $args->{'emit_empty_tags'} ) );
-            }
-
-            $xml->endTag( [ $namespace => 'field' ] );
-        }
-
-        $xml->endTag( [ $namespace => 'fields' ] );
-
-        #
-        # Indices
-        #
-        $xml->startTag( [ $namespace => 'indices' ] );
-        for my $index ( $table->get_indices ) {
-            $xml->startTag( [ $namespace => 'index' ] );
-
-            for my $method ( qw[ fields name options type ] ) {
-                my $val = $index->$method || '';
-                   $val = ref $val eq 'ARRAY' ? join(',', @$val) : $val;
-                $xml->dataElement( [ $namespace => $method ], $val )
-                    if ( defined $val || 
-                        ( !defined $val && $args->{'emit_empty_tags'} ) );
-            }
-
-            $xml->endTag( [ $namespace => 'index' ] );
-        }
-        $xml->endTag( [ $namespace => 'indices' ] );
-
-        #
-        # Constraints
-        #
-        $xml->startTag( [ $namespace => 'constraints' ] );
-        for my $index ( $table->get_constraints ) {
-            $xml->startTag( [ $namespace => 'constraint' ] );
-
-            for my $method ( 
-                qw[ 
-                    deferrable expression fields match_type name 
-                    options on_delete on_update reference_fields
-                    reference_table type 
-                ] 
-            ) {
-                my $val = $index->$method || '';
-                   $val = ref $val eq 'ARRAY' ? join(',', @$val) : $val;
-                $xml->dataElement( [ $namespace => $method ], $val )
-                    if ( defined $val || 
-                        ( !defined $val && $args->{'emit_empty_tags'} ) );
-            }
-
-            $xml->endTag( [ $namespace => 'constraint' ] );
-        }
-        $xml->endTag( [ $namespace => 'constraints' ] );
-
-        $xml->endTag( [ $namespace => 'table' ] );
-    }
-
-    $xml->endTag([ $namespace => 'schema' ]);
-    $xml->end;
-
-    return $io;
-}
-
-1;
+=head1 DESCRIPTION
 
-# -------------------------------------------------------------------
-# The eyes of fire, the nostrils of air,
-# The mouth of water, the beard of earth.
-# William Blake
-# -------------------------------------------------------------------
+Previous versions of SQL::Translator included an XML producer, but the 
+namespace has since been further subdivided.  Therefore, this module is 
+now just just an alias to the XML::SQLFairy producer.
 
-=head1 NAME
+=head1 SEE ALSO
 
-SQL::Translator::Producer::XML - XML output
+SQL::Translator::Producer::XML::SQLFairy.
 
-=head1 SYNOPSIS
+=head1 AUTHOR
 
-  use SQL::Translator::Producer::XML;
+Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
 
-=head1 DESCRIPTION
+=cut
 
-Creates XML output of a schema.
+# -------------------------------------------------------------------
 
-=head1 AUTHOR
+use strict;
+use vars qw[ $VERSION $DEBUG ];
+$VERSION = sprintf "%d.%02d", q$Revision: 1.16 $ =~ /(\d+)\.(\d+)/;
+$DEBUG = 1 unless defined $DEBUG;
 
-Ken Y. Clark E<lt>kclark@cpan.orgE<gt>, darren chamberlain E<lt>darren@cpan.orgE<gt>
+use SQL::Translator::Producer::XML::SQLFairy;
 
-=head1 SEE ALSO
+*produce = \&SQL::Translator::Producer::XML::SQLFairy::produce;
 
-L<XML::Writer>
+1;