[Catalyst] paging with Data::Page

Anne Wainwright anotheranne at fables.co.za
Tue Jul 28 18:57:06 GMT 2009


Hi, Ian

See below,

On Mon, 27 Jul 2009 21:32:36 +0100
Ian Sillitoe <ian at sillit.com> wrote:

> >
> > Could be wrong, but I think the former is causing the resultset to
> > be evaluated as an array and is therefore returning all the entries
> > before the pager is being applied.
> >
> 
> Apologies - I was talking rubbish about the usage of stash being the
> cause (although I do think the resultset is being reset somewhere
> along the line).
> 
> Noting the following, I agree that the 'pager' code is probably
> correct
> > and the 'result' code seems to be the gremlin. How they interact is
> > beyond me
> 
> 
> $result is a DBIx::Class::ResultSet object and is being returned from
> the call to $c->model('Address::Addresses')->search(). This resultset
> object has a method called $result->page($page_number) which sets up
> the database query with the correct start and stop for the given page
> number and entries per page (default=10). It also has a
> $result->pager() method which returns a Data::Page object - this just
> provides a useful container for accessing page-related information of
> the related DB query.
> 
> 
> http://search.cpan.org/~ribasushi/DBIx-Class-0.08108/lib/DBIx/Class/ResultSet.pm
> 
> If the $pager is telling you the correct information (that the query
> only has 10 entries) but this is changing by the time it is being
> rendered in your template then perhaps another call is being made to
> the database (i.e. because something else is changing
> $c->stash->result). Have you tried setting DBIC_TRACE=1 in your
> environment and looking at the logs to check that the database
> queries look sensible?
> 
> You could also check that the resultset at least has the correct
> number of entries just before you leave your search function:
> 
>   $c->log->info( "Current Page: " . $page );
>   $c->log->info( "Results: " . $result->count ); # NB: this will
> perform a DB query
>   $c->log->info( "Leaving 'search' method..." );

this produces 2 items of note if I put it after the search

1.	'Use of uninitialized value $page in concatenation (.) or
	string at ....'
($page is declared in the line  .... = @_)

2.	[info] Current Page: 
	[info] Results: 11
	[info] Leaving 'search' method...
--------------------------------------------

but if I put it after this line
    $page = 1 ; #if($page !~ /^\d+$/);

I get

1.	'Use of uninitialized value $page in pattern match (m//)
at ... '
(a SELECT COUNT( * ) FROM occurs immediately after this )

lower down, we get the run of outputs from
SELECT me.id,

which match up fine to the records expected and delivered, ( I set
DBIC_TRACE=1). Should these not show up before the pattern match
line?

2.	then just at the end

	[info] Current Page: 1
	[info] Results: 11
	[info] Leaving 'search' method...

so pages are assigned in the pager code, but the no of results is
carried over from the search code

These things have a way of getting more complex, so if this info does
not indicate a clear solution, then I don't want to waste valuable time,
rather I might find more in the new book, and must advance further in my
perl studies (not very far into Intermediate Perl at present). Although
I hate being beaten, TIMTOWTDI (whatever)

Anne

> 
> I note that Bindlex used to bring up a warning when the catalyst
> > development server was started, but I do not see this now. Has
> > Bindlex perhaps been un-deprecated?
> >
> 
> Nope -
> http://search.cpan.org/~mstrout/Catalyst-Controller-BindLex-0.05/lib/Catalyst/Controller/BindLex.pm
> 
> 
> Cheers,
> 
> Ian



More information about the Catalyst mailing list