[Rt-commit] r3992 - in Jifty-DBI/trunk: . lib/Jifty/DBI
jesse at bestpractical.com
jesse at bestpractical.com
Thu Oct 27 15:01:03 EDT 2005
Author: jesse
Date: Thu Oct 27 15:01:03 2005
New Revision: 3992
Modified:
Jifty-DBI/trunk/ (props changed)
Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
Log:
r18052 at truegrounds: jesse | 2005-10-28 00:51:46 -0400
* Made ->table work as a class method
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm Thu Oct 27 15:01:03 2005
@@ -1055,18 +1055,35 @@
sub table {
my $self = shift;
- if ( not $self->{__table_name} ) {
- my $class = ref($self);
+ if ( not ref($self) ) {
+ return $self->_guess_table_name();
+ }
+ $self->{__table_name} ||= $self->_guess_table_name;
+
+ return $self->{__table_name};
+}
+
+
+=head2 _guess_table_name
+
+Guesses a table name based on the class's last part.
+
+
+=cut
+
+sub _guess_table_name {
+ my $self = shift;
+ my $class = ref($self) ? ref($self) : $self ;
die "Couldn't turn " . $class . " into a table name"
unless ( $class =~ /(?:\:\:)?(\w+)$/ );
my $table = $1;
$table =~ s/(?<=[a-z])([A-Z]+)/"_" . lc($1)/eg;
$table =~ tr/A-Z/a-z/;
$table = Lingua::EN::Inflect::PL_N($table);
- $self->{__table_name} = $table;
+ return($table);
+
}
- return $self->{__table_name};
-}
+
=head2 _handle
More information about the Rt-commit
mailing list