From: Rafael Kitover Date: Wed, 7 Jul 2010 23:19:07 +0000 (-0400) Subject: set up v8 relbuilder, strip _ref as well as _id X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f3cfe4e62286cc876440aec02e5c0b69e40d6ece;p=dbsrgits%2FDBIx-Class-Schema-Loader.git set up v8 relbuilder, strip _ref as well as _id --- diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index 54126ac..ffddd90 100644 --- a/lib/DBIx/Class/Schema/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -10,7 +10,7 @@ use Scalar::Util qw/ weaken /; # Always remember to do all digits for the version even if they're 0 # i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports # brain damage and presumably various other packaging systems too -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; __PACKAGE__->mk_group_accessors('inherited', qw/ _loader_args diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index ede47bd..1441ff6 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -23,7 +23,7 @@ use DBIx::Class::Schema::Loader::Utils 'split_name'; require DBIx::Class; use namespace::clean; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; __PACKAGE__->mk_group_ro_accessors('simple', qw/ schema @@ -131,7 +131,7 @@ overwriting a dump made with an earlier version. The option also takes a hashref: - naming => { relationships => 'v7', monikers => 'v7' } + naming => { relationships => 'v8', monikers => 'v8' } The keys are: @@ -193,6 +193,11 @@ transition instead of just being lowercased, so C becomes C. If you don't have any CamelCase table or column names, you can upgrade without breaking any of your code. +=item v8 + +This mode tries harder to not have collisions between column accessors and +belongs_to relationship accessors. + =back Dynamic schemas will always default to the 0.04XXX relationship names and won't @@ -201,10 +206,10 @@ and singularization put this in your C file: __PACKAGE__->naming('current'); -Or if you prefer to use 0.07XXX features but insure that nothing breaks in the +Or if you prefer to use 0.08XXX features but insure that nothing breaks in the next major version upgrade: - __PACKAGE__->naming('v7'); + __PACKAGE__->naming('v8'); =head2 generate_pod @@ -489,7 +494,7 @@ L. =cut -my $CURRENT_V = 'v7'; +my $CURRENT_V = 'v8'; my @CLASS_ARGS = qw( schema_base_class result_base_class additional_base_classes @@ -1009,6 +1014,15 @@ sub _relbuilder { $self->relationship_attrs, ); } + elsif ($self->naming->{relationships} eq 'v6') { + require DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_07; + return $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_07->new ( + $self->schema, + $self->inflect_plural, + $self->inflect_singular, + $self->relationship_attrs, + ); + } return $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder->new ( $self->schema, diff --git a/lib/DBIx/Class/Schema/Loader/DBI.pm b/lib/DBIx/Class/Schema/Loader/DBI.pm index a1451eb..98bb7ee 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI.pm @@ -6,7 +6,7 @@ use base qw/DBIx::Class::Schema::Loader::Base/; use Class::C3; use Carp::Clan qw/^DBIx::Class/; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm b/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm index 5dd5884..3137549 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Component/QuotedDefault.pm @@ -4,7 +4,7 @@ use strict; use warnings; use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm index d0cc796..1bc5f7e 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm @@ -9,7 +9,7 @@ use base qw/ use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Informix.pm b/lib/DBIx/Class/Schema/Loader/DBI/Informix.pm index 85fa056..7bb98ee 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Informix.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Informix.pm @@ -8,7 +8,7 @@ use Carp::Clan qw/^DBIx::Class/; use Scalar::Util 'looks_like_number'; use namespace::clean; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm b/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm index 6f73395..61e4733 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/InterBase.pm @@ -8,7 +8,7 @@ use Carp::Clan qw/^DBIx::Class/; use List::Util 'first'; use namespace::clean; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm b/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm index a2cc916..539a88a 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm @@ -6,7 +6,7 @@ use base 'DBIx::Class::Schema::Loader::DBI::Sybase::Common'; use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/ODBC.pm b/lib/DBIx/Class/Schema/Loader/DBI/ODBC.pm index d9dd296..6ba1b1e 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/ODBC.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/ODBC.pm @@ -6,7 +6,7 @@ use base 'DBIx::Class::Schema::Loader::DBI'; use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/ODBC/Firebird.pm b/lib/DBIx/Class/Schema/Loader/DBI/ODBC/Firebird.pm index aeed566..3a590c1 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/ODBC/Firebird.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/ODBC/Firebird.pm @@ -9,7 +9,7 @@ use base qw/ use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/ODBC/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Schema/Loader/DBI/ODBC/Microsoft_SQL_Server.pm index f5431d3..fc21359 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/ODBC/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/ODBC/Microsoft_SQL_Server.pm @@ -8,7 +8,7 @@ use base qw/ use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/ODBC/SQL_Anywhere.pm b/lib/DBIx/Class/Schema/Loader/DBI/ODBC/SQL_Anywhere.pm index 74b7b69..e23d783 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/ODBC/SQL_Anywhere.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/ODBC/SQL_Anywhere.pm @@ -8,7 +8,7 @@ use base qw/ use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm index 7d8f698..cff90f3 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm @@ -9,7 +9,7 @@ use base qw/ use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm index f5eefbb..726273e 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm @@ -9,7 +9,7 @@ use base qw/ use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm index 46472db..18ac2b5 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLAnywhere.pm @@ -9,7 +9,7 @@ use base qw/ /; use Carp::Clan qw/^DBIx::Class/; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm index c5af130..b0a7df2 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/SQLite.pm @@ -10,7 +10,7 @@ use Carp::Clan qw/^DBIx::Class/; use Text::Balanced qw( extract_bracketed ); use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm b/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm index 2b9fc33..715ba59 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Sybase.pm @@ -6,7 +6,7 @@ use base 'DBIx::Class::Schema::Loader::DBI::Sybase::Common'; use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Common.pm b/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Common.pm index 316d46a..53bb810 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Common.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Common.pm @@ -6,7 +6,7 @@ use base 'DBIx::Class::Schema::Loader::DBI'; use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Microsoft_SQL_Server.pm index 5c476de..4e49467 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Microsoft_SQL_Server.pm @@ -6,7 +6,7 @@ use base 'DBIx::Class::Schema::Loader::DBI::MSSQL'; use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Writing.pm b/lib/DBIx/Class/Schema/Loader/DBI/Writing.pm index 9bb7a47..f660833 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Writing.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Writing.pm @@ -1,7 +1,7 @@ package DBIx::Class::Schema::Loader::DBI::Writing; use strict; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; # Empty. POD only. diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm index d7a331a..c07ba6e 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm @@ -6,7 +6,7 @@ use base 'DBIx::Class::Schema::Loader::DBI'; use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm index e3475dd..19dbd94 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder.pm @@ -7,7 +7,7 @@ use Carp::Clan qw/^DBIx::Class/; use Lingua::EN::Inflect::Phrase (); use DBIx::Class::Schema::Loader::Utils 'split_name'; -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; =head1 NAME @@ -188,6 +188,14 @@ sub _relationship_attrs { return \%composite; } +sub _strip__id { + my ($self, $name) = @_; + + $name =~ s/_(?:id|ref)\z//; + + return $name; +} + sub _array_eq { my ($self, $a, $b) = @_; @@ -247,7 +255,7 @@ sub _remote_relname { if(scalar keys %{$cond} == 1) { my ($col) = values %{$cond}; $col = $self->_normalize_name($col); - $col =~ s/_id$//; + $col = $self->_strip__id($col); $remote_relname = $self->_inflect_singular($col); } else { @@ -342,7 +350,7 @@ sub _relnames_and_method { $remote_relname .= $colnames if keys %$cond > 1; $local_relname = $self->_normalize_name($local_table . $colnames); - $local_relname =~ s/_id$//; + $local_relname = $self->_strip__id($local_relname); $local_relname_uninflected = $local_relname; $local_relname = $self->_inflect_plural($local_relname); diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm index b78a89b..5192f47 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_040.pm @@ -7,7 +7,7 @@ use base 'DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_05'; use Carp::Clan qw/^DBIx::Class/; use Lingua::EN::Inflect::Number (); -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; sub _relnames_and_method { my ( $self, $local_moniker, $rel, $cond, $uniqs, $counters ) = @_; diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_05.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_05.pm index f7985b4..8f153ff 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_05.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_05.pm @@ -7,7 +7,7 @@ use base 'DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_06'; use Carp::Clan qw/^DBIx::Class/; use Lingua::EN::Inflect::Number (); -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; sub _to_PL { my ($self, $name) = @_; diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_06.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_06.pm index d0bfb78..1114036 100644 --- a/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_06.pm +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_06.pm @@ -3,11 +3,10 @@ package DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_06; use strict; use warnings; use Class::C3; -use base 'DBIx::Class::Schema::Loader::RelBuilder'; +use base 'DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_07'; use Carp::Clan qw/^DBIx::Class/; -use Lingua::EN::Inflect::Phrase (); -our $VERSION = '0.07001'; +our $VERSION = '0.08000'; sub _normalize_name { my ($self, $name) = @_; @@ -20,7 +19,7 @@ sub _normalize_name { =head1 NAME DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_06 - RelBuilder for -compatibility with DBIx::Class::Schema::Loader version 0.06001 +compatibility with DBIx::Class::Schema::Loader version 0.06000 =head1 DESCRIPTION diff --git a/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_07.pm b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_07.pm new file mode 100644 index 0000000..b5d6cc2 --- /dev/null +++ b/lib/DBIx/Class/Schema/Loader/RelBuilder/Compat/v0_07.pm @@ -0,0 +1,41 @@ +package DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_07; + +use strict; +use warnings; +use Class::C3; +use base 'DBIx::Class::Schema::Loader::RelBuilder'; +use Carp::Clan qw/^DBIx::Class/; + +our $VERSION = '0.08000'; + +sub _strip__id { + my ($self, $name) = @_; + + $name =~ s/_id\z//; + + return $name; +} + +=head1 NAME + +DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_07 - RelBuilder for +compatibility with DBIx::Class::Schema::Loader version 0.07000 + +=head1 DESCRIPTION + +See L and +L. + +=head1 AUTHOR + +See L and L. + +=head1 LICENSE + +This library is free software; you can redistribute it and/or modify it under +the same terms as Perl itself. + +=cut + +1; +# vim:et sts=4 sw=4 tw=0: