fREWdiculous!
20 Jul
Over a year ago I read this blog post. To be honest at the time I thought it was mostly silly and I still feel that way. The things that are important to me in an ORM are capabilities, not subjective prettiness of code. But, I also get tired of typing repetitive things, especially __PACKAGE__->. That’s just too many shift keys! So after working on a few different modules and accruing various bits of knowledge here and there I learned what I needed to to create a sugar layer for DBIx::Class that doesn’t throw the baby out with the bath-water.
I am proud to announce the initial, development version of DBIx::Class::Candy, which should be coming to a CPAN mirror near you very soon. If you just can’t wait, use cpanf to get it right now. The basic gist of it is that you can use:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | package MyApp::Schema::Result::Artist; use DBIx::Class::Candy; table 'artists'; column id => { data_type => 'int', is_auto_increment => 1, }; column name => { data_type => 'varchar', size => 25, is_nullable => 1, }; primary_key 'id'; has_many albums => 'A::Schema::Result::Album', 'artist_id'; 1; |
instead of
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | package MyApp::Schema::Result::Artist; use strict; use warnings; use base 'DBIx::Class::Core'; __PACKAGE__->table('artists'); __PACKAGE__->add_columns( id => { data_type => 'int', is_auto_increment => 1, }, name => { data_type => 'varchar', size => 25, is_nullable => 1, } ); __PACKAGE__->set_primary_key('id'); __PACKAGE__->has_many( albums => 'A::Schema::Result::Album', 'artist_id' ); 1; |
There are a few other features, like having it turn on 5.10 or 5.12 features, use a non standard base, and more. Check it out now!
6 Responses for "Announcing DBIx::Class::Candy"
looks awesome! I’m assuming you could use it to modify a generated schema? (like catalyst docs say to below the md5sum )
@caleb: yep. And of course the __PACKAGE__-> declarations will keep working at the same time.
Personally, I welcome this module. For years the __PACKAGE__ syntax has been bothering me.
There’s one thing which I find amusing, though. I created a very similar module back then in 2006 (it was called DBIx::Class::Sweet). It wasn’t as polished and finished as this one, but it worked in production code.
There was a hailstorm of criticism back then. The actual quote from mst was:
“It is *not* worth being an add-on package.
Please rather than just releasing pointless tiny modules to CPAN will you consider actually talking to the development teams of the respective packages?”
The tone of the email was that this should be part of DBIC and an add-on would be a bad thing.
Anyway, this is just an odd historical curiosity. I really do welcome your module, but I wonder if maybe this could’ve been available to the community at least 3 years earlier with the same degree of polish if it wasn’t for some people being too stubborn (and for me caring too much about criticism).
That’s an interesting story Nilson. I actually spoke with mst before I released this and he specifically mentioned squashing previous attempts, which I am sure yours was an example of. I’m not sure of exactly what makes mine different from yours of course, but if you have ideas of what could be done to improve this by all means let me know.
No ideas, really. It’s looking good.
I guess back then declarative syntax just wasn’t that popular in Perl land as it is today, so there was some resistance. Also, there was no namespace::clean, Devel::Declare or other modern tools and DBIC itself was still fairly new.
I also did a second attempt (this time with mst’s blessing) which was much more convoluted and involved Moose-style declarations. It should be possible to find it in the old DBIC SVN repositories, if they’re still online (Moose-Style-Schema-Declare branch, in case you’re interested). I eventually gave up, as it was useless to me – I just wanted a plain syntax sugar module, not anything too complex.
So, 4 years later we have DBIC::Candy. Well, I guess late is better than never.
[...] DBIx::Class users, prepare to squeal in delight. fREW opened a can of delicious frosting and came up with DBIx::Class::Candy. [...]
Leave a reply