Fixed "database_events."
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / XML / SQLFairy.pm
index 73e1a9f..97877e2 100644 (file)
@@ -1,8 +1,6 @@
 package SQL::Translator::Producer::XML::SQLFairy;
 
 # -------------------------------------------------------------------
-# $Id: SQLFairy.pm,v 1.18 2004-08-19 20:41:32 grommit Exp $
-# -------------------------------------------------------------------
 # Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
 #                    darren chamberlain <darren@cpan.org>,
 #                    Chris Mungall <cjm@fruitfly.org>,
@@ -63,7 +61,7 @@ get mapped to comma seperated lists of values in the attribute.
 Child objects, such as a tables fields, get mapped to child tags wrapped in a
 set of container tags using the plural of their contained classes name.
 
-L<SQL::Translator::Schema::Field>'s extra attribute (a hash of arbitary data) is
+An objects's extra attribute (a hash of arbitary data) is
 mapped to a tag called extra, with the hash of data as attributes, sorted into
 alphabetical order.
 
@@ -165,7 +163,7 @@ To convert your old format files simply pass them through the translator :)
 
 use strict;
 use vars qw[ $VERSION @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.18 $ =~ /(\d+)\.(\d+)/;
+$VERSION = '1.59';
 
 use Exporter;
 use base qw(Exporter);
@@ -214,7 +212,7 @@ sub produce {
     $xml->xmlDecl('UTF-8');
     $xml->comment(header_comment('', ''));
     xml_obj($xml, $schema,
-        tag => "schema", methods => [qw/name database/], end_tag => 0 );
+        tag => "schema", methods => [qw/name database extra/], end_tag => 0 );
 
     #
     # Table
@@ -224,7 +222,7 @@ sub produce {
         debug "Table:",$table->name;
         xml_obj($xml, $table,
              tag => "table",
-             methods => [qw/name order/],
+             methods => [qw/name order extra/],
              end_tag => 0
          );
 
@@ -245,7 +243,7 @@ sub produce {
         xml_obj_children( $xml, $table,
             tag   => 'index',
             collection_tag => "indices",
-            methods => [qw/name type fields options/],
+            methods => [qw/name type fields options extra/],
         );
 
         #
@@ -256,6 +254,18 @@ sub produce {
             methods => [qw/
                 name type fields reference_table reference_fields
                 on_delete on_update match_type expression options deferrable
+                extra
+            /],
+        );
+
+        #
+        # Comments
+        #
+        xml_obj_children( $xml, $table,
+            tag   => 'comment',
+            collection_tag => "comments",
+            methods => [qw/
+                comments
             /],
         );
 
@@ -268,7 +278,7 @@ sub produce {
     #
     xml_obj_children( $xml, $schema,
         tag   => 'view',
-        methods => [qw/name sql fields order/],
+        methods => [qw/name sql fields order extra/],
     );
 
     #
@@ -276,8 +286,8 @@ sub produce {
     #
     xml_obj_children( $xml, $schema,
         tag    => 'trigger',
-        methods => [qw/name database_event action on_table perform_action_when
-            fields order/],
+        methods => [qw/name database_events action on_table perform_action_when
+            fields order extra/],
     );
 
     #
@@ -285,7 +295,7 @@ sub produce {
     #
     xml_obj_children( $xml, $schema,
         tag   => 'procedure',
-        methods => [qw/name sql parameters owner comments order/],
+        methods => [qw/name sql parameters owner comments order extra/],
     );
 
     $xml->endTag([ $Namespace => 'schema' ]);
@@ -308,17 +318,28 @@ sub xml_obj_children {
     my ($name,$collection_name,$methods)
         = @args{qw/tag collection_tag methods/};
     $collection_name ||= "${name}s";
-    my $meth = "get_$collection_name";
+
+    my $meth;
+    if ( $collection_name eq 'comments' ) {
+      $meth = 'comments';
+    } else {
+      $meth = "get_$collection_name";
+    }
 
     my @kids = $parent->$meth;
     #@kids || return;
     $xml->startTag( [ $Namespace => $collection_name ] );
+
     for my $obj ( @kids ) {
-        xml_obj($xml, $obj,
-            tag     => "$name",
-            end_tag => 1,
-            methods => $methods,
-        );
+        if ( $collection_name eq 'comments' ){
+            $xml->dataElement( [ $Namespace => 'comment' ], $obj );
+        } else {
+            xml_obj($xml, $obj,
+                tag     => "$name",
+                end_tag => 1,
+                methods => $methods,
+            );
+        }
     }
     $xml->endTag( [ $Namespace => $collection_name ] );
 }