[Dbix-class] scope in DBIx::Class::Core subclass

Erik Colson eco at ecocode.net
Sun Feb 15 20:51:13 GMT 2015


Hi

I have a Resultsource class as follows:

########################################

package myDB::Atable;

use base qw/ DBIx::Class /;

__PACKAGE__->load_components( qw/ PK::Auto Core / );
__PACKAGE__->table( 'atable' );

__PACKAGE__->add_columns( acolumn => {} );

__PACKAGE__->mk_group_ro_accessors( 'simple' => qw/ aCalculatedField / );

sub get_simple {
  my ( $self, $key ) = @_;
  if ( $key eq 'aCalculatedField' ) {
     return 'CALC: '.String::Util::trim( $self->acolumn );
  }
}

########################################

So now I can query Atable and get the columns 'acolumn' and
'aCalculatedfield'.

the column 'acolumn' will be returned by: $row->get_column('acolumn')
the calculated column will be returned by: $row->get_simple('aCalculatedfield')

However, the code doesn't work if I put a 'use String::Util;' at the top
of the package and replace 'String::Util::trim' by 'trim'. It looks like
the declaration gets out of scope.

How can I keep this code clean ?
-- 
erik colson



More information about the DBIx-Class mailing list