[Dbix-class] Resultset accessors for lazy people, and compile-time checking.

Toby Corkindale toby.corkindale at strategicdata.com.au
Thu Apr 9 07:04:09 GMT 2009


Hi,
Another task I commonly do in DBIC is to access resultsets from the 
$schema object, eg:

$schema->resultset('MyObject')->find(1);

Sometimes I make a mistake, and write:
$schema->resultset('MyObjcet')->find(1);

However that compiles just fine, and won't get picked up until that bit 
of code is hit at runtime - when it fails.

Now there are two problems here.
1) I like things to fail at compile-time when possible.
2) I am fundamentally lazy and like typing less.

Therefore I'd like to propose that DBIC implements direct accessors for 
resultsets, so that I can type:
$schema->MyObject->find(1);

and if I type $schema->MyOBject->find(1) then at compile-time I'll get
"Can't locate object method "MyOBject" via package My::Schema at foo.pl 
line nnn" which is helpful.


So, how do you feel about this?

I might hack up a patch to do this if I get some spare time, but 
wondered if greater minds than mine have already considered it and 
discarded it for being a dreadful idea.

(I'm guessing some code wedged into register_class() or thereabouts 
could do a *{${schema_namespace}::$moniker} = sub { return 
$self->resultset($monikey) }; or something like that. Alternatively via 
AUTOLOAD(), but then you lose the compile-time checking.)


Cheers!
Toby





More information about the DBIx-Class mailing list