use File::Slurp 'slurp';
use Try::Tiny;
use Class::Unload ();
+use Class::Inspector ();
use List::MoreUtils 'apply';
use namespace::clean;
-our $VERSION = '0.07002';
+our $VERSION = '0.07008';
# Glossary:
#
inflect_plural
inflect_singular
relationship_attrs
+ rel_collision_map
_temp_classes
/);
inflect_plural => $base->inflect_plural,
inflect_singular => $base->inflect_singular,
relationship_attrs => $base->relationship_attrs,
+ rel_collision_map => $base->rel_collision_map,
_temp_classes => [],
};
return $remote_relname;
}
+sub _resolve_relname_collision {
+ my ($self, $moniker, $cols, $relname) = @_;
+
+ return $relname if $relname eq 'id'; # this shouldn't happen, but just in case
+
+ if ($self->base->_is_result_class_method($relname)) {
+ if (my $map = $self->rel_collision_map) {
+ for my $re (keys %$map) {
+ if (my @matches = $relname =~ /$re/) {
+ return sprintf $map->{$re}, @matches;
+ }
+ }
+ }
+
+ my $new_relname = $relname;
+ while ($self->base->_is_result_class_method($new_relname)) {
+ $new_relname .= '_rel'
+ }
+
+ warn <<"EOF";
+Relationship '$relname' in source '$moniker' for columns '@{[ join ',', @$cols ]}' collides with an inherited method.
+Renaming to '$new_relname'.
+See "RELATIONSHIP NAME COLLISIONS" in perldoc DBIx::Class::Schema::Loader::Base .
+EOF
+
+ return $new_relname;
+ }
+
+ return $relname;
+}
+
sub generate_code {
my ($self, $local_moniker, $rels, $uniqs) = @_;
my ( $local_relname, $remote_relname, $remote_method ) =
$self->_relnames_and_method( $local_moniker, $rel, \%cond, $uniqs, \%counters );
+ $remote_relname = $self->_resolve_relname_collision($local_moniker, $local_cols, $remote_relname);
+ $local_relname = $self->_resolve_relname_collision($remote_moniker, $remote_cols, $local_relname);
+
push(@{$all_code->{$local_class}},
{ method => 'belongs_to',
args => [ $remote_relname,
if (-f (my $existing_remote_file = $self->base->get_dump_filename($remote_class))) {
my $class = "${remote_class}Temporary";
- if (not do { no strict 'refs'; %{$class . '::'} }) {
+ if (not Class::Inspector->loaded($class)) {
my $code = slurp $existing_remote_file;
$code =~ s/(?<=package $remote_class)/Temporary/g;