X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FAccessorGroup.pm;h=12a8744b2042594794608711532fc6179552b0f8;hb=d009cb7d393292037eff527a9f8bab93860224fb;hp=51dd7bc223b2accac6049f758818e8cd0841ad3f;hpb=fe5d862bdaa631796cb26e5fea232a81458e68f8;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/AccessorGroup.pm b/lib/DBIx/Class/AccessorGroup.pm index 51dd7bc..12a8744 100644 --- a/lib/DBIx/Class/AccessorGroup.pm +++ b/lib/DBIx/Class/AccessorGroup.pm @@ -1,110 +1,70 @@ package DBIx::Class::AccessorGroup; -sub mk_group_accessors { - my($self, $group, @fields) = @_; +use strict; +use warnings; - $self->_mk_group_accessors('make_group_accessor', $group, @fields); -} - - -{ - no strict 'refs'; +use base qw/Class::Accessor::Grouped/; +use Scalar::Util qw/weaken blessed/; +use namespace::clean; - sub _mk_group_accessors { - my($self, $maker, $group, @fields) = @_; - my $class = ref $self || $self; +sub mk_classdata { + shift->mk_classaccessor(@_); +} - # So we don't have to do lots of lookups inside the loop. - $maker = $self->can($maker) unless ref $maker; +sub mk_classaccessor { + my $self = shift; + $self->mk_group_accessors('inherited', $_[0]); + $self->set_inherited(@_) if @_ > 1; +} - foreach my $field (@fields) { - if( $field eq 'DESTROY' ) { - require Carp; - &Carp::carp("Having a data accessor named DESTROY in ". - "'$class' is unwise."); - } +my $successfully_loaded_components; - my $accessor = $self->$maker($group, $field); - my $alias = "_${field}_accessor"; +sub get_component_class { + my $class = $_[0]->get_inherited($_[1]); - *{$class."\:\:$field"} = $accessor - unless defined &{$class."\:\:$field"}; + # It's already an object, just go for it. + return $class if blessed $class; - *{$class."\:\:$alias"} = $accessor - unless defined &{$class."\:\:$alias"}; - } - } -} + if (defined $class and ! $successfully_loaded_components->{$class} ) { + $_[0]->ensure_class_loaded($class); -sub mk_group_ro_accessors { - my($self, $group, @fields) = @_; + mro::set_mro( $class, 'c3' ); - $self->_mk_group_accessors('make_group_ro_accessor', $group, @fields); -} + no strict 'refs'; + $successfully_loaded_components->{$class} + = ${"${class}::__LOADED__BY__DBIC__CAG__COMPONENT_CLASS__"} + = do { \(my $anon = 'loaded') }; + weaken($successfully_loaded_components->{$class}); + } -sub mk_group_wo_accessors { - my($self, $group, @fields) = @_; + $class; +}; - $self->_mk_group_accessors('make_group_wo_accessor', $group, @fields); +sub set_component_class { + shift->set_inherited(@_); } -sub make_group_accessor { - my ($class, $group, $field) = @_; - - my $set = "set_$group"; - my $get = "get_$group"; - - # Build a closure around $field. - return sub { - my $self = shift; +1; - if(@_) { - return $self->set($field, @_); - } - else { - return $self->get($field); - } - }; -} +=head1 NAME -sub make_group_ro_accessor { - my($class, $group, $field) = @_; +DBIx::Class::AccessorGroup - See Class::Accessor::Grouped - my $get = "get_$group"; +=head1 SYNOPSIS - return sub { - my $self = shift; +=head1 DESCRIPTION - if(@_) { - my $caller = caller; - require Carp; - Carp::croak("'$caller' cannot alter the value of '$field' on ". - "objects of class '$class'"); - } - else { - return $self->get($field); - } - }; -} +This class now exists in its own right on CPAN as Class::Accessor::Grouped -sub make_group_wo_accessor { - my($class, $group, $field) = @_; +=head1 FURTHER QUESTIONS? - my $set = "set_$group"; +Check the list of L. - return sub { - my $self = shift; +=head1 COPYRIGHT AND LICENSE - unless (@_) { - my $caller = caller; - require Carp; - Carp::croak("'$caller' cannot access the value of '$field' on ". - "objects of class '$class'"); - } - else { - return $self->set($field, @_); - } - }; -} +This module is free software L +by the L. You can +redistribute it and/or modify it under the same terms as the +L. -1; +=cut