Sunday, December 05, 2010

WebNano - some incompatible API changes ahead

I tried carefully not to document some things that are likely to change in the closest WebNano releases, but the example code I put in the docs needs to be exact and that means it contains some details I have not yet decided are stable. One of these examples is about overriding the local_dispatch. It used to take the path as a string parameter - now it takes an array - i.e. the path split on the '/' character. The past way was more universal as it let the user programmer to specify how to parse the path - but I think splitting on '/' is such a common usage that it justifies the change. And it is not destructive - so if someone really want's to parse the path in a different way then he can join it back.

This change will be in the next WebNano release.

In the longer perspective I am thinking about being more compliant with the Law of Demeter and building the controllers with the needed model parts in their own attributes, instead of accessing them through app. So for example some code in Nblog would change from

$self->app->schema->resultset( 'Article' )->search
to
$self->article_rs->search

Now this can be done by overriding the handle class method - but maybe it needs something more elegant.

3 comments:

cow boy said...

tiny, minor point, but what about

$self->rs('Article')->search

rather than

$self->article_rs->search

"rs" then becomes a "smart" alias for schema->resultset, but retains the method(Table) semantics.

zby said...

Sure - this is also good. In fact I can see also cases where

$self->search_articles

would also make sense. I think this is where TIMTOWTDI does make sense - because I don't know how this will be used. The point is to make it easy to use whatever style the programmer wants.

Anonymous said...

Take a look at DBIx::Class::Schema::ResultSetAccessors