1 package SQL::Translator::Filter::Names;
5 SQL::Translator::Filter::Names - Tweak the names of schema objects.
12 # Lowercase all table names and upper case the first letter of all field
13 # names. (MySql style!)
15 my $sqlt = SQL::Translator->new(
22 'fields' => 'ucfirst',
25 ) || die "SQLFairy error : ".SQL::Translator->error;
26 print($sqlt->translate) || die "SQLFairy error : ".$sqlt->error;
32 use vars qw/$VERSION/;
40 #if ( my $func = $args{tables} ) {
41 # _filtername($_,$func) foreach ( $schema->get_tables );
44 foreach my $type ( qw/tables procedures triggers views/ ) {
45 if ( my $func = $args{$type} ) {
46 my $meth = "get_$type";
47 _filtername($_,$func) foreach $schema->$meth;
52 if ( my $func = $args{fields} ) {
54 foreach map { $_->get_fields } $schema->get_tables ;
59 # _filtername( OBJ, FUNC_NAME )
60 # Update the name attribute on the schema object given using the named filter.
61 # Objects with no name are skipped.
62 # Returns true if the name was changed. Dies if there is an error running func.
65 return unless my $name = $obj->name;
66 $func = _getfunc($func);
67 my $newname = eval { $func->($name) };
68 die "$@" if $@; # TODO - Better message!
69 return if $name eq $newname;
73 # _getfunc( NAME ) - Returns code ref to func NAME or dies.
77 my $func = "SQL::Translator::Filter::Names::$name";
78 die "Table name filter - unknown function '$name'\n" unless exists &$func;
84 # The name munging functions
85 #=============================================================================
86 # Get called with name to munge as first arg and return the new name. Die on
91 sub ucfirst { ucfirst shift; }
93 1; #==========================================================================
101 L<perl(1)>, L<SQL::Translator>
111 Define a bunch of useful groups to run the name filters over. e.g. all, fkeys,
116 e.g. camelcase, titlecase, single word etc.
117 Also a way to pass in a regexp.
119 May also want a way to pass in arguments for the func e.g. prefix.
121 =item Multiple Filters on the same name (filter order)?
123 Do we actually need this, you could just run lots of filters. Would make adding
124 func args to the interface easier.
127 [ 'Names', { all => 'lc' } ],
134 Mind you if you could give the filter a list this wouldn't be a problem!
143 Which is nice. Might have to change the calling conventions for filters.
144 Would also provide an order to run the filters in rather than having to hard
145 code it into the filter it's self.