comparison Lib/Schema/DataSource/CDBIBuilder.pm @ 166:4267a2ac3d46

Added Class::Template, Rewritten SQL::Schema 'use parent' directive instead of 'use base'
author wizard
date Sat, 23 Apr 2011 23:12:06 +0400
parents 16ada169ca75
children
comparison
equal deleted inserted replaced
165:76515373dac0 166:4267a2ac3d46
62 62
63 my $text; 63 my $text;
64 $text = <<ModuleHeader; 64 $text = <<ModuleHeader;
65 #autogenerated script don't edit 65 #autogenerated script don't edit
66 package ${prefix}DBI; 66 package ${prefix}DBI;
67 use base 'Class::DBI'; 67 use parent 'Class::DBI';
68 68
69 require DateTime; 69 require DateTime;
70 70
71 our (\$DSN,\$User,\$Password,\$Init); 71 our (\$DSN,\$User,\$Password,\$Init);
72 \$DSN ||= 'DBI:null'; # avoid warning 72 \$DSN ||= 'DBI:null'; # avoid warning
215 215
216 my $packageName = $this->GeneratePropertyClassName($prop,$prefix); 216 my $packageName = $this->GeneratePropertyClassName($prop,$prefix);
217 my $tableName = $this->{$PropertyTables}->{$prop->Name}->Name; 217 my $tableName = $this->{$PropertyTables}->{$prop->Name}->Name;
218 my $parentName = $this->GenerateClassName($prefix); 218 my $parentName = $this->GenerateClassName($prefix);
219 my $text .= "package $packageName;\n"; 219 my $text .= "package $packageName;\n";
220 $text .= "use base '$baseModule';\n\n"; 220 $text .= "use parent '$baseModule';\n\n";
221 $text .= "__PACKAGE__->table('`$tableName`');\n"; 221 $text .= "__PACKAGE__->table('`$tableName`');\n";
222 $text .= "__PACKAGE__->columns(Essential => qw/_id parent value/);\n"; 222 $text .= "__PACKAGE__->columns(Essential => qw/_id parent value/);\n";
223 $text .= "__PACKAGE__->has_a( parent => '$parentName');\n"; 223 $text .= "__PACKAGE__->has_a( parent => '$parentName');\n";
224 224
225 my $typeValue; 225 my $typeValue;
266 266
267 my $tableName = $this->{$Table}->Name; 267 my $tableName = $this->{$Table}->Name;
268 my $listColumns = join ',', map { '\''. $_->Name . '\''} $this->{$Table}->Columns; 268 my $listColumns = join ',', map { '\''. $_->Name . '\''} $this->{$Table}->Columns;
269 269
270 $text .= "package $packageName;\n"; 270 $text .= "package $packageName;\n";
271 $text .= "use base '$baseModule'". ($this->{$Class}->Name->Name eq 'Map' ? ',\'CDBI::Map\'' : '' ).";\n\n"; 271 $text .= "use parent '$baseModule'". ($this->{$Class}->Name->Name eq 'Map' ? ',\'CDBI::Map\'' : '' ).";\n\n";
272 272
273 $text .= "__PACKAGE__->table('`$tableName`');\n"; 273 $text .= "__PACKAGE__->table('`$tableName`');\n";
274 $text .= "__PACKAGE__->columns(Essential => $listColumns);\n"; 274 $text .= "__PACKAGE__->columns(Essential => $listColumns);\n";
275 275
276 foreach my $prop ( grep { UNIVERSAL::isa($_,'Schema::Property') } $this->{$Class}->ListMembers ) { 276 foreach my $prop ( grep { UNIVERSAL::isa($_,'Schema::Property') } $this->{$Class}->ListMembers ) {