use croak instead of die for user errors.
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / ResultSource.pm
index 8d0b0d8..bc71706 100644 (file)
@@ -48,7 +48,7 @@ sub add_columns {
   my $columns = $self->_columns;
   while (my $col = shift @cols) {
 
-    my $column_info = ref $cols[0] ? shift : {};
+    my $column_info = ref $cols[0] ? shift(@cols) : {};
       # If next entry is { ... } use that for the column info, if not
       # use an empty hashref
 
@@ -57,6 +57,7 @@ sub add_columns {
     $columns->{$col} = $column_info;
   }
   push @{ $self->_ordered_columns }, @added;
+  return $self;
 }
 
 *add_column = \&add_columns;
@@ -143,7 +144,7 @@ sub set_primary_key {
 =head2 primary_columns                                                          
                                                                                 
 Read-only accessor which returns the list of primary keys.
-                                                                                
+
 =cut                                                                            
 
 sub primary_columns {
@@ -223,7 +224,7 @@ created, which calls C<create_related> for the relationship.
 
 sub add_relationship {
   my ($self, $rel, $f_source_name, $cond, $attrs) = @_;
-  die "Can't create relationship without join condition" unless $cond;
+  croak "Can't create relationship without join condition" unless $cond;
   $attrs ||= {};
 
   my %rels = %{ $self->_relationships };
@@ -233,7 +234,7 @@ sub add_relationship {
                   attrs => $attrs };
   $self->_relationships(\%rels);
 
-  return 1;
+  return $self;
 
   # XXX disabled. doesn't work properly currently. skip in tests.
 
@@ -256,7 +257,7 @@ sub add_relationship {
   if ($@) { # If the resolve failed, back out and re-throw the error
     delete $rels{$rel}; # 
     $self->_relationships(\%rels);
-    die "Error creating relationship $rel: $@";
+    croak "Error creating relationship $rel: $@";
   }
   1;
 }
@@ -308,10 +309,10 @@ sub resolve_join {
                  $self->related_source($_)->resolve_join($join->{$_}, $_) }
            keys %$join;
   } elsif (ref $join) {
-    die("No idea how to resolve join reftype ".ref $join);
+    croak ("No idea how to resolve join reftype ".ref $join);
   } else {
     my $rel_info = $self->relationship_info($join);
-    die("No such relationship ${join}") unless $rel_info;
+    croak("No such relationship ${join}") unless $rel_info;
     my $type = $rel_info->{attrs}{join_type} || '';
     return [ { $join => $self->related_source($join)->from,
                -join_type => $type },
@@ -334,8 +335,8 @@ sub resolve_condition {
     my %ret;
     while (my ($k, $v) = each %{$cond}) {
       # XXX should probably check these are valid columns
-      $k =~ s/^foreign\.// || die "Invalid rel cond key ${k}";
-      $v =~ s/^self\.// || die "Invalid rel cond val ${v}";
+      $k =~ s/^foreign\.// || croak "Invalid rel cond key ${k}";
+      $v =~ s/^self\.// || croak "Invalid rel cond val ${v}";
       if (ref $for) { # Object
         #warn "$self $k $for $v";
         $ret{$k} = $for->get_column($v);