Refactor Statistics to clean up printing of debug info and to avoid crashing on
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage.pm
index e422da4..a1c551e 100644 (file)
@@ -7,9 +7,14 @@ use base qw/DBIx::Class/;
 
 use Scalar::Util qw/weaken/;
 use Carp::Clan qw/^DBIx::Class/;
+use IO::File;
 
-__PACKAGE__->load_components(qw/AccessorGroup/);
 __PACKAGE__->mk_group_accessors('simple' => qw/debug debugobj schema/);
+__PACKAGE__->mk_group_accessors('inherited' => 'cursor_class');
+
+__PACKAGE__->cursor_class('DBIx::Class::Cursor');
+
+sub cursor { shift->cursor_class(@_); }
 
 package # Hide from PAUSE
     DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION;
@@ -56,19 +61,11 @@ sub new {
   $new->set_schema($schema);
   $new->debugobj(new DBIx::Class::Storage::Statistics());
 
-  my $fh;
+  #my $fh;
 
   my $debug_env = $ENV{DBIX_CLASS_STORAGE_DBI_DEBUG}
                   || $ENV{DBIC_TRACE};
 
-  if (defined($debug_env) && ($debug_env =~ /=(.+)$/)) {
-    $fh = IO::File->new($1, 'w')
-      or $new->throw_exception("Cannot open trace file $1");
-  } else {
-    $fh = IO::File->new('>&STDERR');
-  }
-
-  $new->debugfh($fh);
   $new->debug(1) if $debug_env;
 
   $new;
@@ -170,6 +167,15 @@ In a nested transaction (calling txn_do() from within a txn_do() coderef) only
 the outermost transaction will issue a L</txn_commit>, and txn_do() can be
 called in void, scalar and list context and it will behave as expected.
 
+Please note that all of the code in your coderef, including non-DBIx::Class
+code, is part of a transaction.  This transaction may fail out halfway, or
+it may get partially double-executed (in the case that our DB connection
+failed halfway through the transaction, in which case we reconnect and
+restart the txn).  Therefore it is best that any side-effects in your coderef
+are idempotent (that is, can be re-executed multiple times and get the
+same result), and that you check up on your side-effects in the case of
+transaction failure.
+
 =cut
 
 sub txn_do {
@@ -314,14 +320,12 @@ sub debugcb {
     }
 }
 
-=head2 cursor
+=head2 cursor_class
 
 The cursor class for this Storage object.
 
 =cut
 
-sub cursor { die "Virtual method!" }
-
 =head2 deploy
 
 Deploy the tables to storage (CREATE TABLE and friends in a SQL-based
@@ -388,7 +392,9 @@ sub select_single { die "Virtual method!" }
 
 =head2 columns_info_for
 
-Returns database type info for the given table's columns.
+Returns metadata for the given source's columns.  This
+is *deprecated*, and will be removed before 1.0.  You should
+be specifying the metadata yourself if you need it.
 
 =cut