X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FProducer%2FYAML.pm;h=782ddb125dcb2cbb157deef5705e5dc0997ef38a;hb=55fa814722ea1e01872298e62783896dae1996b6;hp=68ecd8fbc2b517bfa5c137cd23bd17b471bdfcc1;hpb=44659089c28216f1984873bc4aa8641e2e0e3410;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Producer/YAML.pm b/lib/SQL/Translator/Producer/YAML.pm index 68ecd8f..782ddb1 100644 --- a/lib/SQL/Translator/Producer/YAML.pm +++ b/lib/SQL/Translator/Producer/YAML.pm @@ -1,23 +1,5 @@ package SQL::Translator::Producer::YAML; -# ------------------------------------------------------------------- -# Copyright (C) 2002-2009 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 -# published by the Free Software Foundation; version 2. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA -# ------------------------------------------------------------------- - =head1 NAME SQL::Translator::Producer::YAML - A YAML producer for SQL::Translator @@ -38,32 +20,31 @@ takes a long time. =cut use strict; -use vars qw($VERSION); -$VERSION = '1.59'; +use warnings; +our $VERSION = '1.60'; use YAML qw(Dump); -# ------------------------------------------------------------------- sub produce { my $translator = shift; my $schema = $translator->schema; return Dump({ schema => { - tables => { + tables => { map { ($_->name => view_table($_)) } $schema->get_tables, }, - views => { + views => { map { ($_->name => view_view($_)) } $schema->get_views, }, - triggers => { + triggers => { map { ($_->name => view_trigger($_)) } $schema->get_triggers, }, - procedures => { - map { ($_->name => view_procedure($_)) } + procedures => { + map { ($_->name => view_procedure($_)) } $schema->get_procedures, }, }, @@ -83,7 +64,6 @@ sub produce { }); } -# ------------------------------------------------------------------- sub view_table { my $table = shift; @@ -91,22 +71,21 @@ sub view_table { 'name' => $table->name, 'order' => $table->order, 'options' => $table->options || [], - $table->comments ? ('comments' => $table->comments ) : (), + $table->comments ? ('comments' => [ $table->comments ] ) : (), 'constraints' => [ map { view_constraint($_) } $table->get_constraints ], 'indices' => [ map { view_index($_) } $table->get_indices ], - 'fields' => { + 'fields' => { map { ($_->name => view_field($_)) } - $table->get_fields + $table->get_fields }, keys %{$table->extra} ? ('extra' => { $table->extra } ) : (), }; } -# ------------------------------------------------------------------- sub view_constraint { my $constraint = shift; @@ -126,7 +105,6 @@ sub view_constraint { }; } -# ------------------------------------------------------------------- sub view_field { my $field = shift; @@ -140,12 +118,11 @@ sub view_field { 'is_primary_key' => scalar $field->is_primary_key, 'is_unique' => scalar $field->is_unique, $field->is_auto_increment ? ('is_auto_increment' => 1) : (), - $field->comments ? ('comments' => $field->comments) : (), + $field->comments ? ('comments' => [ $field->comments ]) : (), keys %{$field->extra} ? ('extra' => { $field->extra } ) : (), }; } -# ------------------------------------------------------------------- sub view_procedure { my $procedure = shift; @@ -160,7 +137,6 @@ sub view_procedure { }; } -# ------------------------------------------------------------------- sub view_trigger { my $trigger = shift; @@ -172,11 +148,13 @@ sub view_trigger { 'fields' => scalar $trigger->fields, 'on_table' => scalar $trigger->on_table, 'action' => scalar $trigger->action, + (defined $trigger->scope ? ( + 'scope' => scalar $trigger->scope, + ) : ()), keys %{$trigger->extra} ? ('extra' => { $trigger->extra } ) : (), }; } -# ------------------------------------------------------------------- sub view_view { my $view = shift; @@ -189,7 +167,6 @@ sub view_view { }; } -# ------------------------------------------------------------------- sub view_index { my $index = shift; @@ -204,8 +181,6 @@ sub view_index { 1; -# ------------------------------------------------------------------- - =head1 SEE ALSO SQL::Translator, YAML, http://www.yaml.org/.