From: Ken Youens-Clark Date: Tue, 14 Apr 2009 21:25:28 +0000 (+0000) Subject: Return lines of input in a list context, fixed my name. X-Git-Tag: v0.11008~206 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4d1e8cb43efcd726f085384b1805a232cc550511;p=dbsrgits%2FSQL-Translator.git Return lines of input in a list context, fixed my name. --- diff --git a/lib/SQL/Translator/Producer/ClassDBI.pm b/lib/SQL/Translator/Producer/ClassDBI.pm index 9868675..e6ecd40 100755 --- a/lib/SQL/Translator/Producer/ClassDBI.pm +++ b/lib/SQL/Translator/Producer/ClassDBI.pm @@ -35,18 +35,21 @@ my %CDBI_auto_pkgs = ( # ------------------------------------------------------------------- sub produce { - my $t = shift; - my $create = undef; - local $DEBUG = $t->debug; + my $t = shift; + local $DEBUG = $t->debug; my $no_comments = $t->no_comments; my $schema = $t->schema; my $args = $t->producer_args; + my @create; + if ( my $fmt = $args->{'format_pkg_name'} ) { $t->format_package_name( $fmt ); } + if ( my $fmt = $args->{'format_fk_name'} ) { $t->format_fk_name( $fmt ); } + my $db_user = $args->{'db_user'} || ''; my $db_pass = $args->{'db_password'} || ''; my $main_pkg_name = $args->{'package_name'} || @@ -316,7 +319,7 @@ sub produce { # Now build up text of package. # my $base_pkg = sprintf( 'Class::DBI%s', $from ? "::$from" : '' ); - $create .= join ( "\n", + push @create, join ( "\n", "package $main_pkg_name;\n", $header, "use strict;", @@ -331,7 +334,7 @@ sub produce { my $pkg = $packages{$pkg_name} or next; next unless $pkg->{'pkg_name'}; - $create .= join ( "\n", + push @create, join ( "\n", $sep, "package " . $pkg->{'pkg_name'} . ";", "use base '" . $pkg->{'base'} . "';", @@ -339,40 +342,46 @@ sub produce { ); if ( $from ) { - $create .= - $pkg->{'pkg_name'}."->set_up_table('".$pkg->{'table'}."');\n\n"; + push @create, join('', + $pkg->{'pkg_name'}, + "->set_up_table('", + $pkg->{'table'}, + "');\n\n" + ); } else { my $table = $schema->get_table( $pkg->{'table'} ); my @field_names = map { $_->name } $table->get_fields; - $create .= join("\n", + push @create, join("\n", $pkg_name."->table('".$pkg->{'table'}."');\n", $pkg_name."->columns(All => qw/". join(' ', @field_names)."/);\n\n", ); } - $create .= "\n"; + push @create, "\n"; if ( my $pk = $pkg->{'pk_accessor'} ) { - $create .= $pk; + push @create, $pk; } if ( my @has_a = @{ $pkg->{'has_a'} || [] } ) { - $create .= $_ for @has_a; + push @create, $_ for @has_a; } foreach my $has_many_key ( keys %{ $pkg->{'has_many'} } ) { if ( my @has_many = @{ $pkg->{'has_many'}{$has_many_key} || [] } ) { - $create .= $_ for @has_many; + push @create, $_ for @has_many; } } } - $create .= "1;\n"; + push @create, "1;\n"; - return $create; + return wantarray + ? @create + : join('', @create); } 1; @@ -390,7 +399,7 @@ SQL::Translator::Producer::ClassDBI - create Class::DBI classes from schema Use this producer as you would any other from SQL::Translator. See L for details. -This package utilizes SQL::Translator's formatting methods +This package uses SQL::Translator's formatting methods format_package_name(), format_pk_name(), format_fk_name(), and format_table_name() as it creates classes, one per table in the schema provided. An additional base class is also created for database connectivity @@ -400,4 +409,4 @@ configuration. See L for details on how this works. Allen Day Eallenday@ucla.eduE, Ying Zhang Ezyolive@yahoo.comE, -Ken Y. Clark Ekclark@cpan.orgE. +Ken Youens-Clark Ekclark@cpan.orgE.