I wrote:
> I'm trying to use DBIx::Class::AccessorGroup to make an accessor that
> trims field values, as discussed in another thread. Since I want to use
> this accessor with many tables, I want to define the code in some
> package that is used for all the tables. But I can't figure out where to
> put it and I'm getting confused about base classes.
>
> So for example I have a table NewDomainSegment and I have code like this:
>
> package SU::Schema::NewDomainSegment;
> use base 'SU::Schema';
>
> __PACKAGE__->load_components(qw/AccessorGroup Core/);
> __PACKAGE__->mk_group_ro_accessors( trim => qw/sprot_ac/ );
>
> and in SU::Schema, I have:
>
> sub get_trim
> {
> my ($self, $column) = @_;
>
> my $raw_value = $self->get_column($column);
> $raw_value =~ /^\s*(.*?)\s*$/;
> my $trimmed_value = $1;
> return $trimmed_value;
> }
>
> but it's not working; SU::Schema::NewDomainSegment->can('get_trim') is
> undefined. Is SU::Schema the right place to put the implementation of
> get_trim?
I created an extra class (SU::Shared) that just contains the
implementation of get_trim(). Then I added 'use base "SU::Shared";' to
SU::Schema::NewDomainSegment and I called
SU::Schema::NewDomainSegment->mk_group_ro_accessors(trim => 'sprot_ac');
in my application. That worked, but is there a better way?
I'm using DBIx::Class::Schema::Loader to generate the file for
SU::Schema::NewDomainSegment and I'd like to avoid having to modify the
files it creates, because the database schema changes from time to time
so I need to rerun Loader and I don't want to have to keep re-editing
the subclasses it generates.
Is there a way to tell DBIx::Class::Schema::Loader to include the use
base statement in the subclasses? Or some other place to implement the
method so it gets inherited automatically?
Thanks, Dave
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/