X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FRelationships.pm;h=d6120bcf8b2cbb92e115ef9e4fe4b3a73eddf51b;hb=93b7182b41791a8253cef12f02805eaab05df91d;hp=77bc7884ba920ebf33d7220b3da5ac6bbf566152;hpb=1097f5e4f0e0a5fc2c30851cb9a0141712a85fcf;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/CDBICompat/Relationships.pm b/lib/DBIx/Class/CDBICompat/Relationships.pm index 77bc788..d6120bc 100644 --- a/lib/DBIx/Class/CDBICompat/Relationships.pm +++ b/lib/DBIx/Class/CDBICompat/Relationships.pm @@ -3,7 +3,7 @@ package # hide from PAUSE use strict; use warnings; - +use Sub::Name (); use base qw/Class::Data::Inheritable/; use Clone; @@ -23,8 +23,19 @@ Emulate C, C, C and C. =cut sub has_a { + my($self, $col, @rest) = @_; + + $self->_declare_has_a($col, @rest); + $self->_mk_inflated_column_accessor($col); + + return 1; +} + + +sub _declare_has_a { my ($self, $col, $f_class, %args) = @_; - $self->throw_exception( "No such column ${col}" ) unless $self->has_column($col); + $self->throw_exception( "No such column ${col}" ) + unless $self->has_column($col); $self->ensure_class_loaded($f_class); my $rel_info; @@ -55,10 +66,15 @@ sub has_a { has_a => $col, $rel_info ); - + return 1; } +sub _mk_inflated_column_accessor { + my($class, $col) = @_; + + return $class->mk_group_accessors('inflated_column' => $col); +} sub has_many { my ($class, $rel, $f_class, $f_key, $args) = @_; @@ -106,7 +122,8 @@ sub has_many { no strict 'refs'; no warnings 'redefine'; my $post_proc = sub { my $o = shift; $o = $o->$_ for @f_method; $o; }; - *{"${class}::${rel}"} = + my $name = join '::', $class, $rel; + *$name = Sub::Name::subname $name, sub { my $rs = shift->search_related($rel => @_); $rs->{attrs}{record_filter} = $post_proc;