3 use FS::Schema qw( dbdef_dist );
8 # add a new FS/FS/table.pm
11 my %ut = ( #just guesses
19 my $dbdef_table = dbdef_dist->table($table)
20 or die "define table in Schema.pm first";
21 my $primary_key = $dbdef_table->primary_key;
23 open(SRC,"<eg/table_template.pm") or die $!;
24 -e "FS/FS/$table.pm" and die "FS/FS/$table.pm already exists!";
25 open(DEST,">FS/FS/$table.pm") or die $!;
27 while (my $line = <SRC>) {
29 $line =~ s/table_name/$table/g;
31 if ( $line =~ /^=item\s+field\s+-\s+description\s*$/ ) {
33 foreach my $column ( $dbdef_table->columns ) {
34 print DEST "=item $column\n\n";
35 if ( $column eq $primary_key ) {
36 print DEST "primary key\n\n";
38 print DEST "$column\n\n";
43 } elsif ( $line=~ /^(\s*)\$self->ut_numbern\('primary_key'\)\s*/ ) {
45 print DEST "$1\$self->ut_numbern('$primary_key')\n"
50 $line =~ /^(\s*)\|\|\s+\$self->ut_number\('validate_other_fields'\)\s*/
53 foreach my $column ( grep { $_ ne $primary_key } $dbdef_table->columns ) {
54 my $ut = $ut{$dbdef_table->column($column)->type};
55 $ut .= 'n' if $dbdef_table->column($column)->null;
56 print DEST "$1|| \$self->ut_$ut('$column')\n";
69 # add to FS/FS/Mason.pm
73 # 1. disablable (have an option to turn it off)
74 # 2. documented in the schema change docs
76 #my $magic = '# Sammath Naur';
77 #system("perl -pi -e 's/$magic/use FS::$table;\n $magic/' FS/FS/Mason.pm");
83 open(TEST,">FS/t/$table.t") or die $!;
85 BEGIN { \$| = 1; print "1..1\\n" }
86 END {print "not ok 1\\n" unless \$loaded;}
94 # add them to MANIFEST
97 system('cvs edit FS/MANIFEST');
99 open(MANIFEST,">>FS/MANIFEST") or die $!;
100 print MANIFEST "FS/$table.pm\n",