Fixed syntax errors.
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / YAML.pm
1 package SQL::Translator::Producer::YAML;
2
3 # -------------------------------------------------------------------
4 # $Id: YAML.pm,v 1.2 2003-10-08 17:27:40 dlc Exp $
5 # -------------------------------------------------------------------
6 # Copyright (C) 2003 darren chamberlain <darren@cpan.org>,
7 #
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.
11 #
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.
16 #
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
20 # 02111-1307  USA
21 # -------------------------------------------------------------------
22
23 use strict;
24 use vars qw($VERSION);
25 $VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/;
26
27 use YAML qw(Dump);
28
29 sub produce {
30     my $translator  = shift;
31     my $schema      = $translator->schema;
32
33     return Dump({
34         schema => {
35             map { ($_->name => view_table($_)) } $schema->get_tables
36         }
37     });
38 }
39
40 sub view_table {
41     my $table = shift;
42     my $name = $table->name;
43
44     return {
45         map { ($_->name => view_field($_)) } $table->get_fields
46     };
47 }
48
49 sub view_field {
50     my $field = shift;
51
52     return {
53         'order' => scalar $field->order,
54         'name'  => scalar $field->name,
55         'type'  => scalar $field->data_type,
56         'size'  => [ $field->size ],
57         'extra' => { $field->extra },
58     };
59 }
60
61 1;
62
63 =head1 NAME
64
65 SQL::Translator::Producer::YAML - A YAML producer for SQL::Translator