[Dbix-class] Class methods on result source classes

Pedro Melo melo at simplicidade.org
Mon Sep 3 13:22:49 GMT 2007


Hi,

I'm using a "fat model" approach in a small project and one thing  
that keeps popping up is class methods.

For example, I usually have a can_edit() method in a base class that  
all my sources use. This allows me to do something like this:

   $schema->resultset('Books')->find($id)->can_edit($current_user);

The can_edit() method will receive as "self" the Book with the $id,  
and it will just work.

But if I want to write a can_create(), I do something like:

$schema->resultset('Books')->->can_create($current_user);

or like this

$schema->resultset('Books')->result_class->can_create($current_user);

The second one is longer but easier to do because it doesn't require  
me to create a ResultSet class for each source.

Any common, more elegant, solution to this problems?

Thanks,
-- 
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: melo at simplicidade.org
Use XMPP!





More information about the DBIx-Class mailing list