[jifty-devel] Easier model usage
Kang-min Liu
gugod at gugod.org
Sat Aug 30 09:21:07 EDT 2008
Hi, cl, jesse
The introduced names are not top-level package names but package
global functions.
"Foo" is a method imported from Jifty::ModelHelpers with body defined
there with some
code looks like this:
*{"Foo"} = sub {
my @arg = @_;
my $obj = Jifty->app_class(Model => "Foo");
if (@arg == 1) {
$obj->load(@arg)
}
elsif (@arg % 2 == 0) {
$obj->load_by_cols(@arg);
}
return $obj;
};
Only they are generated in the body of Jifty::ModelHelpers package.
Not even playing any import
magic.
These functions won't be there unless people say "use
Jifty::ModelHelpers" of course.
And I almost always need something this easy in View.pm and
Dispatcher.pm, and only
in there. So I feel this is should be quite sane.
There could be also be import tags like, :all, :collections, :models.
Or even dynamic tags
like ":foo", which exports only Foo and FooCollection.
A globally availble M() function helped me for a while but today I
figured out the shortcut
is only required in View.pm and Dispatcher.pm. Not in my Action code
because I seldom
defined my own action code. Therefore I decided to try to push this
further and came
up with ModelHelpers.pm.
I don't really have any idea that prevents namespace clobbering issue
yet... but now I recalled
that I released a roughly working version of DBIx::CSSQuery before
which let you fetch database
records with CSS selector syntax.
With that, to do:
Jifty->app_class(Model => "Foo")->load(1);
You say:
db("foo[id=1]")
(I did'nt named it DBIx::jQuery for some reason but maybe I should
have done that.)
If I can managed to use that in my Jifty code base it'll make me super
happy too. :)
/me really wants to reuse my learnings.
--
Cheers,
Kang-min Liu
More information about the jifty-devel
mailing list