package SQL::Translator::Producer::SqlfXML;
# -------------------------------------------------------------------
-# $Id: SqlfXML.pm,v 1.4 2003-08-14 12:03:00 grommit Exp $
+# $Id: SqlfXML.pm,v 1.5 2003-08-20 17:13:58 kycl4rk Exp $
# -------------------------------------------------------------------
# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
# darren chamberlain <darren@cpan.org>,
-# Chris Mungall <cjm@fruitfly.org>
+# Chris Mungall <cjm@fruitfly.org>,
+# Mark Addison <mark.addison@itn.co.uk>.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
use strict;
use warnings;
use vars qw[ $VERSION ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
use Exporter;
use base qw(Exporter);
use XML::Writer;
my $namespace = 'http://sqlfairy.sourceforge.net/sqlfairy.xml';
-my $name = 'sqlt';
+my $name = 'sqlt';
{
our ($translator,$PArgs,$schema);
sub debug { $translator->debug(@_,"\n"); } # Shortcut.
sub produce {
- $translator = shift;
- $PArgs = $translator->producer_args;
- $schema = $translator->schema;
-
- my $io = IO::Scalar->new;
+ $translator = shift;
+ $PArgs = $translator->producer_args;
+ $schema = $translator->schema;
+ my $io = IO::Scalar->new;
my $xml = XML::Writer->new(
OUTPUT => $io,
NAMESPACES => 1,
sub xml_obj {
my ($xml, $obj, %args) = @_;
- my $tag = $args{tag};
- my @meths = @{$args{methods}};
- my $attrib_values = $PArgs->{attrib_values};
- my $empty_tag = 0;
- my $end_tag = $args{end_tag};
+ my $tag = $args{'tag'} || '';
+ my $end_tag = $args{'end_tag'} || '';
+ my $attrib_values = $PArgs->{'attrib_values'} || '';
+ my @meths = @{ $args{'methods'} };
+ my $empty_tag = 0;
+
if ( $attrib_values and $end_tag ) {
$empty_tag = 1;
$end_tag = 0;
if ( $attrib_values ) {
my %attr = map {
my $val = $obj->$_;
- ($_ => ref($val) eq 'ARRAY' ? join(", ",@$val) : $val);
+ ($_ => ref($val) eq 'ARRAY' ? join(', ', @$val) : $val);
} @meths;
- foreach (keys %attr) { delete $attr{$_} unless defined $attr{$_}; }
+ foreach ( keys %attr ) { delete $attr{$_} unless defined $attr{$_}; }
$empty_tag ? $xml->emptyTag( [ $namespace => $tag ], %attr )
: $xml->startTag( [ $namespace => $tag ], %attr );
}
else {
$xml->startTag( [ $namespace => $tag ] );
- xml_objAttr($xml,$obj, @meths);
+ xml_objAttr( $xml, $obj, @meths );
}
- $xml->endTag( [ $namespace => $tag ] ) if $end_tag;
+ $xml->endTag( [ $namespace => $tag ] ) if $end_tag;
}
# Takes an xml writer, a Schema::* object and a list of methods and adds the
# XML for those methods.
sub xml_objAttr {
my ($xml, $obj, @methods) = @_;
- my $emit_empty = $PArgs->{emit_empty_tags};
- for my $method (@methods) {
+ my $emit_empty = $PArgs->{'emit_empty_tags'};
+
+ for my $method ( @methods ) {
my $val = $obj->$method;
debug " ".ref($obj)."->$method=",
(defined $val ? "'$val'" : "<UNDEF>");
next unless $emit_empty || defined $val;
- $val = "" if not defined $val;
+ $val = '' if not defined $val;
$val = ref $val eq 'ARRAY' ? join(',', @$val) : $val;
debug " Adding Attr:".$method."='",$val,"'";
$xml->dataElement( [ $namespace => $method ], $val );
=head1 AUTHOR
Ken Y. Clark E<lt>kclark@cpan.orgE<gt>,
-darren chamberlain E<lt>darren@cpan.orgE<gt>,
-mark addison E<lt>mark.addison@itn.co.ukE<gt>,
+Darren Chamberlain E<lt>darren@cpan.orgE<gt>,
+Mark Addison E<lt>mark.addison@itn.co.ukE<gt>.
=head1 SEE ALSO