Commit | Line | Data |
d3fad399 |
1 | package SQL::Translator::Producer::YAML; |
2 | |
3 | # ------------------------------------------------------------------- |
af53e4ec |
4 | # $Id: YAML.pm,v 1.2 2003-10-08 17:27:40 dlc Exp $ |
d3fad399 |
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); |
af53e4ec |
25 | $VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/; |
d3fad399 |
26 | |
af53e4ec |
27 | use YAML qw(Dump); |
d3fad399 |
28 | |
29 | sub produce { |
30 | my $translator = shift; |
31 | my $schema = $translator->schema; |
32 | |
af53e4ec |
33 | return Dump({ |
34 | schema => { |
35 | map { ($_->name => view_table($_)) } $schema->get_tables |
36 | } |
37 | }); |
d3fad399 |
38 | } |
39 | |
40 | sub view_table { |
41 | my $table = shift; |
af53e4ec |
42 | my $name = $table->name; |
d3fad399 |
43 | |
af53e4ec |
44 | return { |
45 | map { ($_->name => view_field($_)) } $table->get_fields |
46 | }; |
d3fad399 |
47 | } |
48 | |
49 | sub view_field { |
50 | my $field = shift; |
51 | |
af53e4ec |
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 | }; |
d3fad399 |
59 | } |
60 | |
af53e4ec |
61 | 1; |
d3fad399 |
62 | |
af53e4ec |
63 | =head1 NAME |
d3fad399 |
64 | |
af53e4ec |
65 | SQL::Translator::Producer::YAML - A YAML producer for SQL::Translator |