sub new {
my ($class, $rs, $column) = @_;
$class = ref $class if ref $class;
-
- my $object_ref = { _column => $column,
- _parent_resultset => $rs };
-
- my $new = bless $object_ref, $class;
- $new->throw_exception("column must be supplied") unless ($column);
+ my $new = bless { _column => $column, _parent_resultset => $rs }, $class;
+ $new->throw_exception("column must be supplied") unless $column;
return $new;
}
sub next {
my $self = shift;
-
$self->{_resultset} = $self->{_parent_resultset}->search(undef, {select => [$self->{_column}], as => [$self->{_column}]}) unless ($self->{_resultset});
my ($row) = $self->{_resultset}->cursor->next;
return $row;
=cut
sub min {
- my $self = shift;
- return $self->func('MIN');
+ return shift->func('MIN');
}
=head2 max
=cut
sub max {
- my $self = shift;
- return $self->func('MAX');
+ return shift->func('MAX');
}
=head2 sum
=cut
sub sum {
- my $self = shift;
- return $self->func('SUM');
+ return shift->func('SUM');
}
=head2 func
=cut
sub func {
- my $self = shift;
- my $function = shift;
-
+ my ($self,$function) = @_;
my ($row) = $self->{_parent_resultset}->search(undef, {select => {$function => $self->{_column}}, as => [$self->{_column}]})->cursor->next;
return $row;
}
my ($class, $attrs) = @_;
$class = ref $class if ref $class;
- my $new = { %{$attrs || {}}, _resultset => undef };
- bless $new, $class;
-
+ my $new = bless { %{$attrs || {}} }, $class;
$new->{resultset_class} ||= 'DBIx::Class::ResultSet';
$new->{resultset_attributes} = { %{$new->{resultset_attributes} || {}} };
$new->{_ordered_columns} = [ @{$new->{_ordered_columns}||[]}];
'call it on the schema instead.'
) if scalar @_;
- # disabled until we can figure out a way to do it without consistency issues
- #
- #return $self->{_resultset}
- # if ref $self->{_resultset} eq $self->resultset_class;
- #return $self->{_resultset} =
-
return $self->resultset_class->new(
$self, $self->{resultset_attributes}
);