[Dbix-class] Class methods on result source classes

Evaldas Imbrasas evaldas at imbrasas.com
Mon Sep 3 16:13:49 GMT 2007


If you all you need is to be able to write class methods for your
model classes, you can use DBIx::Class::ResultSetManager:
http://search.cpan.org/~ash/DBIx-Class-0.08006/lib/DBIx/Class/ResultSetManager.pm


On 9/3/07, Pedro Melo <melo at simplicidade.org> wrote:
> 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!
>
>
>
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.rawmode.org
>


-- 
-----------------------------------------------------
Evaldas Imbrasas
http://www.imbrasas.com



More information about the DBIx-Class mailing list