X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FAccessorGroup.pm;h=dd99da3a9696eabd336bf1285c1fdd95dbf21393;hb=5ef3e508fa20d477b62406146cdca0ae658c10dd;hp=a7e85be061135179abe0d0adb9056d533100dca8;hpb=c687b87e860c97257542dda2b14c0137f6fbc583;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/AccessorGroup.pm b/lib/DBIx/Class/AccessorGroup.pm index a7e85be..dd99da3 100644 --- a/lib/DBIx/Class/AccessorGroup.pm +++ b/lib/DBIx/Class/AccessorGroup.pm @@ -3,7 +3,22 @@ package DBIx::Class::AccessorGroup; use strict; use warnings; -use NEXT; +use Carp::Clan qw/^DBIx::Class/; + +=head1 NAME + +DBIx::Class::AccessorGroup - Lets you build groups of accessors + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +This class lets you build groups of accessors that will call different +getters and setters. + +=head1 METHODS + +=cut sub mk_group_accessors { my($self, $group, @fields) = @_; @@ -25,8 +40,7 @@ sub mk_group_accessors { foreach my $field (@fields) { if( $field eq 'DESTROY' ) { - require Carp; - &Carp::carp("Having a data accessor named DESTROY in ". + carp("Having a data accessor named DESTROY in ". "'$class' is unwise."); } @@ -89,8 +103,7 @@ sub make_group_ro_accessor { if(@_) { my $caller = caller; - require Carp; - Carp::croak("'$caller' cannot alter the value of '$field' on ". + croak("'$caller' cannot alter the value of '$field' on ". "objects of class '$class'"); } else { @@ -109,8 +122,7 @@ sub make_group_wo_accessor { unless (@_) { my $caller = caller; - require Carp; - Carp::croak("'$caller' cannot access the value of '$field' on ". + croak("'$caller' cannot access the value of '$field' on ". "objects of class '$class'"); } else { @@ -119,4 +131,46 @@ sub make_group_wo_accessor { }; } +sub get_simple { + my ($self, $get) = @_; + return $self->{$get}; +} + +sub set_simple { + my ($self, $set, $val) = @_; + return $self->{$set} = $val; +} + +sub get_component_class { + my ($self, $get) = @_; + if (ref $self) { + return $self->{$get}; + } else { + $get = "_$get"; + return $self->can($get) ? $self->$get : undef; + } +} + +sub set_component_class { + my ($self, $set, $val) = @_; + eval "require $val"; + if (ref $self) { + return $self->{$set} = $val; + } else { + $set = "_$set"; + return $self->can($set) ? $self->$set($val) : $self->mk_classdata($set => $val); + } +} + 1; + +=head1 AUTHORS + +Matt S. Trout + +=head1 LICENSE + +You may distribute this code under the same terms as Perl itself. + +=cut +