[Catalyst] uri_with and ACCEPT_CONTEXT

Dermot paikkos at googlemail.com
Thu Jan 7 19:23:05 GMT 2010


Hi,

I have a page which lists lots of items.  I need links on the page
that will alter the number of items per page and to do page
navigation. I want the code for the page navigation in my non-catalyst
class. I'm using C::Model::Factory at the moment, but I might need to
use PerRequest. The uri_with() looks like it could really conveniently
alter the url EG:

for ( qw/12 24 48 96/ ) {
    link = $c->uri_with( per_page => $_);
}

I hope I've understood what uri_with does! Should I be able to take
the current url and substitue http://host.domain.com/list?per_page=12
-> http://host.domain.com/list?per_page=24...etc?


I tried the recipe from the latest book but the config part is
tripping me up. $self is not available to the Model's config
(__PACKAGE__->config) and I am not sure how I can. You can't declare
$self as a package variable, it has to be a class before it's args()
is called.

=======  MyApp::Model::Lister =========

use parent 'Catalyst::Model::Factory';
use Moose;
use namespace::autoclean;

__PACKAGE__->config(
        class       => 'MyApp::Local::Class',
        args        => { arg    =>  $self->arg};     # Global symbol
"$self" requires...
        );


sub ACCEPT_CONTEXT {
    my ($self, $c) = @_;
    my $new = $self->meta->clone_object($self, arg => $c->uri_with('') );
    $new = $self->meta->clone_object($self, arg => $c->req->path  );
    return $new;
}
=============================


Again, I'm a little unsure here because I want to take uri_with into
MyApp::Local::Class and use it there. Is that what ACCEPT_CONTEXT can
do? Can anyone tell me how I can get $self into the config or is there
some other way to get args into the constructor?
Thanks,
Dp.



More information about the Catalyst mailing list