Today has been a really long day -- Jifty hacking by the day and Parrot hacking (IMCC lexer reentrancy) by the night. Happily, both proved to be fruitful.
The Jifty hacking part involves putting a declarative layer around Jifty::Action, so we can use the same Model-side Jifty::DBI::Schema syntax for Controller-side action parameters. It's now realized at the moose branch: the sample actions in t/ has been updated to reflect the new syntax:
The best part of this is that the declaration sugar is generally applicable: I've abstracted out all the build-your-own-DSL-kit sugar into a new CPAN module Object::Declare: It's not Jifty-dependent nor Moose-dependent, and there is no source filter or symbol table pollution involved.
However, changing from a custom-method interface:
sub arguments {
return { foo => { label => _("bar"), default => time } };
}
to a static declaration interface that occurs at compile time:
param foo =>
label is _("bar"),
default is time;
means that we need to find a way to express runtime-calculated values. For example, the _("bar") call above for localization needs to use the current user's language handle, and the time call should be different each time the action is requested.
To solve that problem, I uploaded another new CPAN module, Scalar::Defer, so one can write:
my $t = defer { time };
warn $t; # 1153209784
sleep 10;
warn $t; # 1153209794
In addition to the call-by-name defer {...}, that module also provides the call-by-need lazy {...}, which works the same way as in Pugs -- i.e. it memoizes the first result value and reuse it on subsequent calls. By using deferred values, we get to aggressively memoize all statically-known parameter values, yet retain full flexibility for runtime-calculated fields. Yay for hybrid evaluation strategies!

Recent Comments