From 4edbd2aea409be95d403fe9b9ff53d167d87d9fc Mon Sep 17 00:00:00 2001 From: Arthur Axel 'fREW' Schmidt Date: Mon, 30 Mar 2015 13:33:48 -0500 Subject: [PATCH] Fix HRI'd resultsets to use coderef if passed --- Changes | 1 + lib/Web/Util/ExtPaging.pm | 2 +- t/basic.t | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 912b9f1..cee5572 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for {{$dist->name}} {{$NEXT}} + - Fix HRI'd resultsets to use coderef if passed (Good find Nathan Dyck!) 0.001002 2014-11-03 16:21:05-06:00 America/Chicago - Transparently support resultsets using HRI (Wes Malone) diff --git a/lib/Web/Util/ExtPaging.pm b/lib/Web/Util/ExtPaging.pm index c14cb37..5bcc2b2 100644 --- a/lib/Web/Util/ExtPaging.pm +++ b/lib/Web/Util/ExtPaging.pm @@ -23,7 +23,7 @@ sub ext_paginate { } return ext_parcel( - $resultset->result_class->isa('DBIx::Class::ResultClass::HashRefInflator') ? + $resultset->result_class->isa('DBIx::Class::ResultClass::HashRefInflator') && !ref $method ? [$resultset->all] : [map $_->$method, $resultset->all], $resultset->is_paged diff --git a/t/basic.t b/t/basic.t index 900471c..3c24a6d 100644 --- a/t/basic.t +++ b/t/basic.t @@ -128,4 +128,28 @@ my $rs = $schema->resultset('Stations')->search(undef, { }) }, 'ext_parcel correctly builds structure'; } + +{ + my $rs = $schema->resultset('Stations')->search(undef, { + columns => ['id'], + order_by => 'id', + rows => 3, + page => 1, + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + }); + + my $data = ext_paginate($rs, sub { +{ id => $_[0]{id} + 1 } } ); + + cmp_deeply $data, { + total => 9, + data=> set({ + id => 2, + },{ + id => 3, + },{ + id => 4, + }) + }, 'ext_paginate w/ HRI works with coderef'; +} + done_testing;