[Dbix-class] Re: Working with Moose - Best Practices
Roman Daniel
roman.daniel at davosro.cz
Fri Dec 30 00:43:11 GMT 2011
Rodrigo <rodrigolive <at> gmail.com> writes:
>
> In my neck of the woods, for large applications, we're using the DataMapper
pattern (separation of business model and database layer), which translates into
having a model layer like yours:
>
>
> Model::User->create('bob');
>
>
> Which in turn wraps, into a single transaction if possible, calls such as:
>
>
>
> $schema->resultset('User')->create({ username=>'bob', password_reset=>1 );
>
> $schema->resultset('UsersInGroup')->create( ... );
> $ldap->create_user( ... );
> $email->notify_admin( "user $user created" );
> $email->notify_user("your password is..." );
>
> I don't think you need use_moose=>1 if you're going towards this pattern. I
recommend taking a look into MooseX::Types::DBIx::Class, which can be combined
with delegation ("handles") and method modifiers ("around") that help you
simplify method calls:
>
>
>
> has 'row' => ( is=>'rw', isa=>Row, handles=>[qw/insert create delete/] );
> has 'rs' => (is=>'rw', isa=>ResultSet, handles=>[qw/search find/] );
>
(I apologize for late questions) How do you pass $schema to Model::User::create?
Do you use class accessor or do you have separate bussiness object wrapping
resultset?
Roman Daniel
More information about the DBIx-Class
mailing list