Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / UniqueIdentifier.pm
index 92e7c15..e6f3466 100644 (file)
@@ -38,7 +38,8 @@ In which case it is used as the name of database function to create a new GUID,
 =item coderef
 
 In which case the coderef should return a string GUID, using L<Data::GUID>, or
-whatever GUID generation method you prefer.
+whatever GUID generation method you prefer. It is passed the C<$self>
+L<DBIx::Class::Storage> reference as a parameter.
 
 =back
 
@@ -56,16 +57,14 @@ sub _is_guid_type {
   return $data_type =~ $GUID_TYPE;
 }
 
-sub insert {
+sub _prefetch_autovalues  {
   my $self = shift;
-  my ($source, $to_insert) = @_;
-
-  my $col_info = $source->columns_info;
+  my ($source, $col_info, $to_insert) = @_;
 
   my %guid_cols;
   my @pk_cols = $source->primary_columns;
-  my %pk_cols;
-  @pk_cols{@pk_cols} = ();
+  my %pk_col_idx;
+  @pk_col_idx{@pk_cols} = ();
 
   my @pk_guids = grep {
     $col_info->{$_}{data_type}
@@ -79,13 +78,11 @@ sub insert {
     $col_info->{$_}{data_type} =~ $GUID_TYPE
     &&
     $col_info->{$_}{auto_nextval}
-  } grep { not exists $pk_cols{$_} } $source->columns;
+  } grep { not exists $pk_col_idx{$_} } $source->columns;
 
   my @get_guids_for =
     grep { not exists $to_insert->{$_} } (@pk_guids, @auto_guids);
 
-  my $updated_cols = {};
-
   for my $guid_col (@get_guids_for) {
     my $new_guid;
 
@@ -93,33 +90,32 @@ sub insert {
 
     if (not defined $guid_method) {
       $self->throw_exception(
-        'You must set new_guid on your storage. See perldoc '
+        'You must set new_guid() on your storage. See perldoc '
        .'DBIx::Class::Storage::DBI::UniqueIdentifier'
       );
     }
 
     if (ref $guid_method eq 'CODE') {
-      $new_guid = $guid_method->();
+      $to_insert->{$guid_col} = $guid_method->($self);
     }
     else {
-      ($new_guid) = $self->_get_dbh->selectrow_array("SELECT $guid_method");
+      ($to_insert->{$guid_col}) = $self->_get_dbh->selectrow_array("SELECT $guid_method");
     }
-
-    $updated_cols->{$guid_col} = $to_insert->{$guid_col} = $new_guid;
   }
 
-  $updated_cols = { %$updated_cols, %{ $self->next::method(@_) } };
-
-  return $updated_cols;
+  return $self->next::method(@_);
 }
 
-=head1 AUTHOR
+=head1 FURTHER QUESTIONS?
 
-See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
+Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
 
-=head1 LICENSE
+=head1 COPYRIGHT AND LICENSE
 
-You may distribute this code under the same terms as Perl itself.
+This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
+by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
+redistribute it and/or modify it under the same terms as the
+L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
 
 =cut