From: Mark Addison Date: Thu, 8 Jul 2004 20:37:26 +0000 (+0000) Subject: Added producer args to control indenting, newlines and namespace prefixing. X-Git-Tag: v0.06~41 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=983ed64670f3dcb274afe77de0810158c923dce7;p=dbsrgits%2FSQL-Translator.git Added producer args to control indenting, newlines and namespace prefixing. --- diff --git a/lib/SQL/Translator/Producer/XML/SQLFairy.pm b/lib/SQL/Translator/Producer/XML/SQLFairy.pm index 7db90bd..2b4834d 100644 --- a/lib/SQL/Translator/Producer/XML/SQLFairy.pm +++ b/lib/SQL/Translator/Producer/XML/SQLFairy.pm @@ -1,7 +1,7 @@ package SQL::Translator::Producer::XML::SQLFairy; # ------------------------------------------------------------------- -# $Id: SQLFairy.pm,v 1.13 2004-07-08 19:34:29 grommit Exp $ +# $Id: SQLFairy.pm,v 1.14 2004-07-08 20:37:26 grommit Exp $ # ------------------------------------------------------------------- # Copyright (C) 2003 Ken Y. Clark , # darren chamberlain , @@ -101,7 +101,33 @@ To see a complete example of the XML translate one of your schema :) =head1 ARGS -Doesn't take any extra arguments. +=over 4 + +=item add_prefix + +Set to true to use the default namespace prefix of 'sqlf', instead of using +the default namespace for +C + +e.g. + + + + + + + +=item prefix + +Set to the namespace prefix you want to use for the +C + +e.g. + + + + +=back =head1 LEGACY FORMAT @@ -121,7 +147,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.13 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/; use Exporter; use base qw(Exporter); @@ -144,13 +170,19 @@ sub produce { my $translator = shift; my $schema = $translator->schema; $PArgs = $translator->producer_args; + my $newlines = defined $PArgs->{newlines} ? $PArgs->{newlines} : 1; + my $indent = defined $PArgs->{indent} ? $PArgs->{indent} : 2; my $io = IO::Scalar->new; + + my $prefix = ""; + $prefix = $Name if $PArgs->{add_prefix}; + $prefix = $PArgs->{prefix} if $PArgs->{prefix}; my $xml = XML::Writer->new( OUTPUT => $io, NAMESPACES => 1, - PREFIX_MAP => { $Namespace => $Name }, - DATA_MODE => 1, - DATA_INDENT => 2, + PREFIX_MAP => { $Namespace => $prefix }, + DATA_MODE => $newlines, + DATA_INDENT => $indent, ); $xml->xmlDecl('UTF-8'); diff --git a/t/17sqlfxml-producer.t b/t/17sqlfxml-producer.t index 0f032e7..bfe808c 100644 --- a/t/17sqlfxml-producer.t +++ b/t/17sqlfxml-producer.t @@ -47,31 +47,31 @@ use SQL::Translator::Producer::XML::SQLFairy; my ($obj,$ans,$xml); $ans = < - - - - comment on id field - - - - - - - - - - - - - - - - - - - - + + + + + comment on id field + + + + + + + + + + + + + + + + + + +
+
EOXML $obj = SQL::Translator->new( @@ -99,11 +99,11 @@ eq_or_diff $xml, $ans, "XML looks right"; my ($obj,$ans,$xml); $ans = < - - select name, age from person - - + + + select name, age from person + + EOXML $obj = SQL::Translator->new( @@ -143,11 +143,11 @@ EOXML my ($obj,$ans,$xml); $ans = < - - update modified=timestamp(); - - + + + update modified=timestamp(); + + EOXML $obj = SQL::Translator->new( @@ -190,12 +190,12 @@ EOXML my ($obj,$ans,$xml); $ans = < - - select foo from bar - Go Sox! - - + + + select foo from bar + Go Sox! + + EOXML $obj = SQL::Translator->new(