1 package SQL::Translator::Producer::YAML;
3 # -------------------------------------------------------------------
4 # $Id: YAML.pm,v 1.1 2003-10-08 16:33:13 dlc Exp $
5 # -------------------------------------------------------------------
6 # Copyright (C) 2003 darren chamberlain <darren@cpan.org>,
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; version 2.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # -------------------------------------------------------------------
24 use vars qw($VERSION);
25 $VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/;
27 use SQL::Translator::Utils qw(header_comment);
30 my $translator = shift;
31 my $schema = $translator->schema;
36 #header_comment('', '# '),
37 map { view_table($_) } $schema->get_tables;
48 map { view_field($_) } $table->get_fields;
55 sprintf("%s: %s" => $field->name),
57 sprintf " %s: %s" => $_->[0], view($_->[1])
59 [ 'order' => $field->order ],
60 [ 'name' => $field->name ],
61 [ 'type' => $field->data_type ],
62 [ 'size' => [ $field->size ] ],
63 [ 'extra' => { $field->extra } ],
70 { '' => sub { $_[0] },
71 'SCALAR' => sub { ${$_[0]} },
72 'ARRAY' => sub { join "\n - $_", @{$_[0]} },
73 'HASH' => sub { join "\n " => map { "$_: $_[0]->{$_}" } keys %{$_[0]} },
74 }->{ref $thingie}->($thingie);