The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Egg::Plugin::DBIC - Plugin for Egg::Model::DBIC.

SYNOPSIS

  use Egg qw/ DBIC /;
  
  # $e->model('dbic::myschema');
  my $schema= $e->schema_myschema;
  
  # $e->model('dbic::myschema::hogetable');
  my $table= $e->schema_myschema->resultset('HogeTable');
  
  # The data base handler is acquired beginning the transaction.
  #  If AutoCommit is effective, the transaction is not done.
  my $dbh= $e->dbh('myschema');
    or
  my $dbh= $e->begin_myschema;
  
  # Committing and rollback.
  #  If AutoCommit is effective, nothing is done.
  $e->commit_myschema;
    or
  $e->rollback_myschema;
  
  # Delay committing or rollback.
  # It settles at the end of processing and the transaction is shut.
  $e->commit_ok( myschema => 1 );
    or
  $e->rollback_ok( myschema => 1 );

DESCRIPTION

It is a plugin that conveniently makes Egg::Model::DBIC available only a little.

The controller is made the setup of Egg::Model::DBIC to use it, and for this plugin to be read.

  use Egg qw/
    .............
    DBIC
    /;

This plugin adds a concerned some methods to Schema set up with Egg::Model::DBIC to the project.

METHODS

dbh ([LABEL_NAME])

The data base handler is returned.

LABEL_NAME is a label name to call Schema. The part of first 'dbic::' of the label name is omissible.

  my $schema= $e->dbh('myschema');

When LABEL_NAME is omitted, all the data base handlers that Egg::Model::DBIC reads are returned by the list.

  my @schema= $e->dbh;

If the transaction is effective, the transaction is begun at the same time.

begin_[schema_name]

The function is the same as 'dbh' method.

Because here uses the label name of Schema for the method name, it is not necessary to specify the argument.

  my $dbh= $e->begin_myschema;

commit_ok ([LABEL_NAME], [FLAG_BOOL]);

The delay committing is done when the transaction is effective. This is used to settle at the end of processing and to commit it.

LABEL_NAME is a label name to call Schema. It is not omissible.

FLAG_BOOL is a flag whether execute it. When 0 is redefined after it keeps effective, it becomes a cancellation.

  # The delay committing is effectively done.
  $e->commit_ok( myschema => 1 );
  
  # The delay committing is canceled.
  $e->commit_ok( myschema => 0 );

rollback_ok (LABEL_NAME], [FLAG_BOOL])

The delay rollback is done when the transaction is effective. This is used to settle at the end of processing and to do the rollback.

However, this plugin is effective, not effective the delay committing, either always does the rollback by the transaction, and completes processing. Therefore, I think that it will use it by the cancellation usage when the delay committing is effectively done.

Even if the delay committing of same Schema effectively becomes it, it is disregarded when this method is made effective.

  # The delay rollback is made effective.
  $e->rollback_ok( myschema => 1 );
  
  # The delay rollback is invalidated.
  $e->rollback_ok( myschema => 0 );

schema_[schema_name]

The object of the schema is returned.

This is made to be able to write the place usually assumed the $e->model('dbic::myschema') only a little short.

  my $schema= $e->schema_myschema;

commit_[schema_name]

If the transaction is effective, it immediately commits it.

  $e->commit_myschema;

rollback_[schema_name]

If the transaction is effective, the rollback is immediately done.

  $e->rollback_myschema;

SEE ALSO

Egg::Release, Egg::Model::DBIC,

AUTHOR

Masatoshi Mizuno <lushe@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2008 Bee Flag, Corp. <http://egg.bomcity.com/>, All Rights Reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.