Nuked _select_columns, the last vestige of class-based evil
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / ResultSet.pm
index 53e06ef..cfe45ce 100644 (file)
@@ -2,8 +2,10 @@ package DBIx::Class::ResultSet;
 
 use strict;
 use warnings;
+use Carp qw/croak/;
 use overload
         '0+'     => 'count',
+        'bool'   => sub { 1; },
         fallback => 1;
 use Data::Page;
 use Storable;
@@ -41,10 +43,11 @@ sub new {
   $attrs = Storable::dclone($attrs || {}); # { %{ $attrs || {} } };
   my %seen;
   my $alias = ($attrs->{alias} ||= 'me');
-  if (!$attrs->{select}) {
+  if ($attrs->{cols} || !$attrs->{select}) {
+    delete $attrs->{as} if $attrs->{cols};
     my @cols = ($attrs->{cols}
                  ? @{delete $attrs->{cols}}
-                 : $source->result_class->_select_columns);
+                 : $source->columns);
     $attrs->{select} = [ map { m/\./ ? $_ : "${alias}.$_" } @cols ];
   }
   $attrs->{as} ||= [ map { m/^$alias\.(.*)$/ ? $1 : $_ } @{$attrs->{select}} ];
@@ -284,7 +287,7 @@ on the resultset and counts the results of that.
 sub count {
   my $self = shift;
   return $self->search(@_)->count if @_ && defined $_[0];
-  die "Unable to ->count with a GROUP BY" if defined $self->{attrs}{group_by};
+  croak "Unable to ->count with a GROUP BY" if defined $self->{attrs}{group_by};
   unless (defined $self->{count}) {
     my $attrs = { %{ $self->{attrs} },
                   select => { 'count' => '*' },
@@ -353,7 +356,7 @@ Sets the specified columns in the resultset to the supplied values
 
 sub update {
   my ($self, $values) = @_;
-  die "Values for update must be a hash" unless ref $values eq 'HASH';
+  croak "Values for update must be a hash" unless ref $values eq 'HASH';
   return $self->{source}->storage->update(
            $self->{source}->from, $values, $self->{cond});
 }
@@ -367,7 +370,7 @@ cascade triggers, ->update will not.
 
 sub update_all {
   my ($self, $values) = @_;
-  die "Values for update must be a hash" unless ref $values eq 'HASH';
+  croak "Values for update must be a hash" unless ref $values eq 'HASH';
   foreach my $obj ($self->all) {
     $obj->set_columns($values)->update;
   }
@@ -409,7 +412,7 @@ sense for queries with page turned on.
 sub pager {
   my ($self) = @_;
   my $attrs = $self->{attrs};
-  die "Can't create pager for non-paged rs" unless $self->{page};
+  croak "Can't create pager for non-paged rs" unless $self->{page};
   $attrs->{rows} ||= 10;
   $self->count;
   return $self->{pager} ||= Data::Page->new(
@@ -481,16 +484,6 @@ sub find_or_create {
   return defined($exists) ? $exists : $self->create($hash);
 }
 
-=head2 self
-
-  my $rs = $rs->self;
-
-Just returns the resultset. Useful for Template Toolkit.
-
-=cut
-
-sub self { shift; }
-
 =head1 ATTRIBUTES
 
 The resultset takes various attributes that modify its behavior.
@@ -551,11 +544,13 @@ for an unpaged resultset.
 
 For a paged resultset, how many rows per page
 
-=head2 group_by
+=head2 group_by (listref)
 
-A list of columns to group by (note that 'count' doesn't work on grouped
+A listref of columns to group by (note that 'count' doesn't work on grouped
 resultsets)
 
+  group_by => [qw/ column1 column2 ... /]
+
 =head2 distinct
 
 Set to 1 to group by all columns