[Dbix-class] [PATCH] supply avg_rs and avg functions for ResultSetColumn.pm

Terrence Brannon schemelab at gmail.com
Fri Apr 2 14:44:09 GMT 2010


There was some discussion of doing this in a higher-order way, but for
right now, AVG is common enough that this patch should be integrated:

Index: ResultSetColumn.pm
===================================================================
--- ResultSetColumn.pm	(revision 9073)
+++ ResultSetColumn.pm	(working copy)
@@ -381,6 +381,48 @@

 sub sum_rs { return shift->func_rs('SUM') }

+
+=head2 avg
+
+=over 4
+
+=item Arguments: none
+
+=item Return Value: $average
+
+=back
+
+  my $avg_year = $year_col->avg();
+
+Wrapper for ->func. Returns the averge value of the column in the
+resultset (or C<undef> if there are none).
+
+=cut
+
+sub avg {
+  return shift->func('AVG');
+}
+
+=head2 avg_rs
+
+=over 4
+
+=item Arguments: none
+
+=item Return Value: $resultset
+
+=back
+
+  my $rs = $year_col->avg_rs();
+
+Wrapper for ->func_rs for function AVG().
+
+=cut
+
+sub min_rs { return shift->func_rs('AVG') }
+
+
+
 =head2 func

 =over 4



More information about the DBIx-Class mailing list