[Dbix-class] Inflated column with custom accessor

Ivan Fomichev ifomichev at gmail.com
Wed Jun 6 16:34:14 GMT 2007


Hello, all,

I've met a strange behaviour of an inflated column if it is given with
a custom accessor. It does not return inflated result if accessed with
a custom accessor method or get_column (get_inflated_column works all
right). On the other hand, inflate_column creates a 'default' accessor
method, that was not implicitly asked to be created. That unasked
accessor works all right too.

Is it the right thing? Is there a reasonable workaround (do I use
wrong syntax perhaps)?

Here's an example:

-- BEGIN test.sql

create table test_inflate (
    inflated varchar(255)
);

-- BEGIN Schema/TestInflate.pm

package Schema::TestInflate;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('test_inflate');
__PACKAGE__->add_columns('inflated' => { accessor => 'i' } );
__PACKAGE__->inflate_column('inflated' => {
    inflate => sub { shift() . '_inflated' },
    deflate => sub { ( shift() =~ /(.*)_inflated/ )[0] },
} );

1;

-- BEGIN test.pl

#!/usr/bin/perl
use strict;
use warnings;

use DBIx::Class;

package Schema;
use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_classes();

package main;

my $s = Schema->connect('DBI:mysql:test:fomichev.dev.dss', 'admin', 'higer4');
my $rs = $s->resultset('TestInflate');
$rs->delete();
$rs->create( { inflated => 'test' } );

my $i = $rs->first();
print $i->inflated(), "\n"; # test_inflated
print $i->i(), "\n";           # test

-- END

Regards,
Ivan



More information about the Dbix-class mailing list