The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

DBIx::Class::Service - Aggregate DBIC processes between multiple tables.

VERSION

version 0.02

SYNOPSIS

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);

METHODS

load_service_methods()

Load code attributes and return a pair of attribute and method name as hashref.

SEE ALSO

DBIx::Class::ServiceManager
DBIx::Class::ServiceProxy

AUTHOR

Toru Yamaguchi, <zigorou@cpan.org>

BUGS

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.

COPYRIGHT & LICENSE

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.