[jifty-devel] Easier model usage

Sterling Hanenkamp sterling at hanenkamp.com
Mon Sep 1 19:56:58 EDT 2008

I like the record(foo) idea. We use something similar at work. In our equivalent of Jifty::Object we have a model() method that does essentially this (but with a grosser ORM).


-----Original Message-----
From: Jesse Vincent <jesse at bestpractical.com>
Sent: Saturday, August 30, 2008 2:00 AM
To: Nifty apps in a Jiffy <jifty-devel at lists.jifty.org>
Subject: Re: [jifty-devel] Easier model usage

On Aug 29, 2008, at 11:22 PM, Chia-liang Kao wrote:
> IIRC you previously had a hack M("Foo") which gives you the foo model,
> maybe we can do something like M("Foo", Load => 1) and M("Foo",
> LoadByCols => foo => 'abc', email => xyz at foo.com') ?  I'd prefer
> polluting the namespace in a more finite and deterministic way, rather
> than having all models generating toplevel package.
> so maybe M() for model helper and MC() for collection helper?  I guess
> that would help a lot for plugin writers as well.

I actually sort of wonder if we jsut want a shortcut for


Class(Model => 'Foo');
Class(Model => 'FooCollection');

But at that point, I get sad about the toplevel pollution.

And hrm. I don't know if a middleground will make gugod happy. It  
almost feels like we sort of want a functional subset of jifty to do  
what gugod is looking for.

> I've been very frustrated to write something like:
> my $m = Jifty->app_class(Model => "Foo")->new
> $m->load($id);

Right now, the best we can do is:

my $m = Jifty->app_class(Model => "Foo")->load($id);

Gugod's extension gives us:

my $m = Foo(1);

CL's proposal gets us to:

M(Foo => Load => 1);

Gugod's syntax is very very pretty but does have a namespace  
clobbering issue and can't generalize easily to other kinds of classes  
without more stompyness.

I suppose we could do something like:

my $m = Jifty->record('Foo')->load($id);

or even

my $m = record('foo')->load($id);

We might be able to get to:

my $m = record foo load ($id);

Other ideas?

jifty-devel mailing list
jifty-devel at lists.jifty.org

More information about the jifty-devel mailing list