How to dynamic change the table name of a resultset with DBIx

Sometime it's necessary to have a resultset with a dynamic table name. Here an easy and smart way to dynamic change your table name :

my $dsn = "YOUR DNS";
my $schema = new My::Schema;
$schema->connect($dsn);

#get source of your resultset, use clone of your schema to prevent modification of the original table name
#this way you can use it in a thread system
my $src = $schema->clone()->source('YOUR RESULTSET');
$src->name("YOUR NEW TABLE NAME");

#now you can do a search
my $result = $src->resultset->search;
while(my $row = $result->next) {
//do your job
}

Done !

Short URL

Comments