DBIx::Class::Service - Aggregate DBIC processes between multiple tables.
version 0.02
Each service class example:
package MySchema::Service::User; use strict; use warnings; use base qw(DBIx::Class::Service); sub add_user: Transaction { my ($class, $schema, $args) = @_; my $user_rs = $schema->resultset('User'); my $user = $user_rs->create({ user_seq => undef, user_id => $args->{user_id}, password_digest => crypt($args->{password}, $args->{user_id}), }); $user->create_related('profiles', { name => $args->{name}, nickname => $args->{nickname}, }); return $user; } sub authenticate: DataSource { my ($class, $schema, $user_id, $password) = @_; return $schema->resultset('User')->find({ user_id => $user_id, password_digest => crypt($password, $user_id) }); } 1;
And your schema class:
package MySchema::Schema; use strict; use warnings; use base 'DBIx::Class::Schema'; __PACKAGE__->load_classes; __PACKAGE__->load_components(qw/ServiceManager/); __PACKAGE__->load_services({ 'MySchema::Service' => [qw/ User /] }); 1;
Using:
use MySchema::Schema; my $schema = MySchema::Schema->connect($dsn, $dbuser, $dbpass); ### note: please see arguments. do not need $schema $schema->service('User')->add_user($args);
Load code attributes and return a pair of attribute and method name as hashref.
Toru Yamaguchi, <zigorou@cpan.org>
<zigorou@cpan.org>
Please report any bugs or feature requests to bug-dbix-class-service@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-dbix-class-service@rt.cpan.org
Copyright 2008 Toru Yamaguchi, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install DBIx::Class::Service, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class::Service
CPAN shell
perl -MCPAN -e shell install DBIx::Class::Service
For more information on module installation, please visit the detailed CPAN module installation guide.