fREWdiculous!
31 Jan
I just released a new version of DBIx::Class::Helpers and it has two new components: DBIx::Class::Helper::ResultSet::ResultClassDWIM and DBIx::Class::Helper::Schema::GenerateSource.
This component solves an issue I’ve seen both by myself and with my coworkers; it’s too hard to remember/type the following:
1 2 3 | my $rs = $schema->resultset('Foo')->search($q, { result_class => 'DBIx::Class::ResultClass::HashRefInflator', }); |
So I wrote this component which will let you generically write:
1 2 3 | my $rs = $schema->resultset('Foo')->search($q, { result_class => '::HashRefInflator', }); |
or use the specially hardcoded:
1 2 3 | my $rs = $schema->resultset('Foo')->search($q, { result_class => '::HRI', }); |
Handy right?
This component is a little more unusual. The idea is to take care of some of the issues I mentioned here. It doesn’t solve everything due to some design issues in DBIx::Class, which I hope to take care of soon. Basically the idea is that instead of the boilerplate files that you get when you use DBIx::Class::Helper::Row::SubClass, you can instead just do the following in your schema:
1 2 3 4 5 6 7 8 9 | package Foo::Schema; __PACKAGE__->load_components('Helper::Schema::GenerateSource'); # ... __PACKAGE->generate_source(User => 'MyCompany::Result::User'); 1; |
The main issue is that even though this correctly associates a new source to the schema, you cannot currently add relationships to the source. I’ll make another post when I fix that, but I doubt I’ll get it into the next release of DBIx::Class.
In other news I’m doing some pretty sweet stuff with the SQL generation code in DBIx::Class and I hope it will be ready for the next release. I’ll post more when that’s released.
2 Responses for "New stuff in DBIx::Class::Helpers"
I thought you wrote a ‘candy’ package or something at some point which allowed you to just write package not __PACKAGE__ or something similar… (no time to look it up atm) but it seems to me it was not __PACKAGE-> so why the difference? or is my memory rotten?
@caleb: DBIx::Class::Candy is just for defining results. Using it you don’t need __PACKAGE__ or package or anything like that. I didn’t create something similar for the schema as it doesn’t get edited as much as result classes do.
Leave a reply