5 use FS::Schema qw( dbdef_dist );
12 # add a new FS/FS/table.pm
15 my %ut = ( #just guesses
23 my $dbdef_table = dbdef_dist->table($table)
24 or die "define table in Schema.pm first";
25 my $primary_key = $dbdef_table->primary_key;
27 open(SRC,"<eg/table_template.pm") or die $!;
28 -e "FS/FS/$table.pm" and die "FS/FS/$table.pm already exists!";
29 open(DEST,">FS/FS/$table.pm") or die $!;
31 while (my $line = <SRC>) {
33 $line =~ s/table_name/$table/g;
35 if ( $line =~ /^=item\s+field\s+-\s+description\s*$/ ) {
37 foreach my $column ( $dbdef_table->columns ) {
38 print DEST "=item $column\n\n";
39 if ( $column eq $primary_key ) {
40 print DEST "primary key\n\n";
42 print DEST "$column\n\n";
47 } elsif ( $line=~ /^(\s*)\$self->ut_numbern\('primary_key'\)\s*/ ) {
49 print DEST "$1\$self->ut_numbern('$primary_key')\n"
54 $line =~ /^(\s*)\|\|\s+\$self->ut_number\('validate_other_fields'\)\s*/
57 foreach my $column ( grep { $_ ne $primary_key } $dbdef_table->columns ) {
58 my $ut = $ut{$dbdef_table->column($column)->type};
59 $ut .= 'n' if $dbdef_table->column($column)->null;
60 print DEST "$1|| \$self->ut_$ut('$column')\n";
73 # add to FS/FS/Mason.pm
76 my $magic = '# Sammath Naur';
77 system("perl -pi -e 's/$magic/use FS::$table;\n $magic/' FS/FS/Mason.pm")
84 open(TEST,">FS/t/$table.t") or die $!;
86 BEGIN { \$| = 1; print "1..1\\n" }
87 END {print "not ok 1\\n" unless \$loaded;}
95 # add them to MANIFEST
98 system('cvs edit FS/MANIFEST');
100 open(MANIFEST,">>FS/MANIFEST") or die $!;
101 print MANIFEST "FS/$table.pm\n",