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


DBIx-Class-Service documentation  | view source Contained in the DBIx-Class-Service distribution.

Index


NAME

Top

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

VERSION

Top

version 0.02

SYNOPSIS

Top

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

Top

load_service_methods()

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

SEE ALSO

Top

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

AUTHOR

Top

Toru Yamaguchi, <zigorou@cpan.org>

BUGS

Top

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

Top


DBIx-Class-Service documentation  | view source Contained in the DBIx-Class-Service distribution.