package SQL::Translator::Producer::HTML;
# -------------------------------------------------------------------
-# $Id: HTML.pm,v 1.7 2003-08-20 13:50:47 dlc Exp $
+# $Id: HTML.pm,v 1.8 2003-08-20 14:32:49 dlc Exp $
# -------------------------------------------------------------------
# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>
#
# -------------------------------------------------------------------
use strict;
-use CGI;
use Data::Dumper;
use vars qw[ $VERSION ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/;
use SQL::Translator::Schema::Constants;
use SQL::Translator::Utils qw(header_comment);
my $schema_name = $schema->name || 'Schema';
my $args = $t->producer_args;
my $q = defined $args->{'pretty'}
- ? do { require CGI::Pretty; CGI::Pretty->new }
- : CGI->new;
+ ? do { require CGI::Pretty;
+ import CGI::Pretty;
+ CGI::Pretty->new }
+ : do { require CGI;
+ import CGI;
+ CGI->new };
my $title = $args->{'title'} || "Description of $schema_name";
my $html = $q->start_html(
--- /dev/null
+#!/usr/bin/perl
+# vim: set ft=perl:
+
+use strict;
+
+use SQL::Translator;
+use Test::More tests => 25;
+
+my (%format_X_name, $tr, $ret);
+
+my %format_X_name = (
+ format_table_name => sub { "table_$_[0]" },
+ format_package_name => sub { "package_$_[0]" },
+ format_fk_name => sub { "fk_$_[0]" },
+ format_pk_name => sub { "pk_$_[0]" },
+);
+
+ok($tr = SQL::Translator->new);
+
+is(($ret = $tr->format_table_name("foo")), "foo",
+ '$tr->format_table_name("foo") == "foo"');
+is(($ret = $tr->format_package_name("foo")), "foo",
+ '$tr->format_package_name("foo") == "foo"');
+is(($ret = $tr->format_fk_name("foo")), "foo",
+ '$tr->format_fk_name("foo") == "foo"');
+is(($ret = $tr->format_pk_name("foo")), "foo",
+ '$tr->format_pk_name("foo") == "foo"');
+
+ok($tr->format_table_name($format_X_name{format_table_name}),
+ '$tr->format_table_name(sub { "table_$_[0]" })');
+is(($ret = $tr->format_table_name("foo")), "table_foo",
+ '$tr->format_table_name("foo") == "table_foo"');
+
+ok($tr->format_package_name($format_X_name{format_package_name}),
+ '$tr->format_package_name(sub { "package_$_[0]" })');
+is(($ret = $tr->format_package_name("foo")), "package_foo",
+ '$tr->format_package_name("foo") == "package_foo"');
+
+ok($tr->format_fk_name($format_X_name{format_fk_name}),
+ '$tr->format_fk_name(sub { "fk_$_[0]" })');
+is(($ret = $tr->format_fk_name("foo")), "fk_foo",
+ '$tr->format_fk_name("foo") == "fk_foo"');
+
+ok($tr->format_pk_name($format_X_name{format_pk_name}),
+ '$tr->format_pk_name(sub { "pk_$_[0]" })');
+is(($ret = $tr->format_pk_name("foo")), "pk_foo",
+ '$tr->format_pk_name("foo") == "pk_foo"');
+
+
+ok($tr->format_table_name($format_X_name{format_table_name}),
+ '$tr->format_table_name(sub { "table_$_[0]" })');
+is(($ret = $tr->format_table_name("foo")), "table_foo",
+ '$tr->format_table_name("foo") == "table_foo"');
+
+ok($tr->format_package_name($format_X_name{format_package_name}),
+ '$tr->format_package_name(sub { "package_$_[0]" })');
+is(($ret = $tr->format_package_name("foo")), "package_foo",
+ '$tr->format_package_name("foo") == "package_foo"');
+
+ok($tr->format_fk_name($format_X_name{format_fk_name}),
+ '$tr->format_fk_name(sub { "fk_$_[0]" })');
+is(($ret = $tr->format_fk_name("foo")), "fk_foo",
+ '$tr->format_fk_name("foo") == "fk_foo"');
+
+ok($tr->format_pk_name($format_X_name{format_pk_name}),
+ '$tr->format_pk_name(sub { "pk_$_[0]" })');
+is(($ret = $tr->format_pk_name("foo")), "pk_foo",
+ '$tr->format_pk_name("foo") == "pk_foo"');
+
+is(($ret = $tr->format_table_name($format_X_name{format_table_name}, "foo")), "table_foo",
+ '$tr->format_table_name(sub { "table_$_[0]" }, "foo") == "table_foo"');
+
+is(($ret = $tr->format_package_name($format_X_name{format_package_name}, "foo")), "package_foo",
+ '$tr->format_package_name(sub { "package_$_[0]" }, "foo") == "package_foo"');
+
+is(($ret = $tr->format_fk_name($format_X_name{format_fk_name}, "foo")), "fk_foo",
+ '$tr->format_fk_name(sub { "fk_$_[0]" }, "foo") == "fk_foo"');
+
+is(($ret = $tr->format_pk_name($format_X_name{format_pk_name}, "foo")), "pk_foo",
+ '$tr->format_pk_name(sub { "pk_$_[0]" }, "foo") == "pk_foo"');