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;
}