I am working on a script which the user calls a route called /add_news but that route should be able to call itself with a query parameter. This is the smallest amount of code I can come up with to do what I want but it fails every time. The Mojolicious documentation is not clear enough for me to understand what I need to do.

#!/usr/bin/perl use Mojolicious::Lite; get '/add_news' => sub { my $self = shift; my $offset = $self->param('offset') // 0; if ( $offset > 9 ) { $self->render(text => "offset = $offset\n"); } else { $self->redirect_to('/add_news?offset=10'); } }; app->start;

When the code runs with and the offset is greater than 10 I see the rendered text but once I use an offset less than 10 I get a 302 error. I understand it is redirecting but when I look at the output the URL looks correct.

[Tue Jun 18 23:24:49 2013] [info] Listening at "http://*:3000". Server available at http://127.0.0.1:3000. [Tue Jun 18 23:24:57 2013] [debug] Your secret passphrase needs to be +changed!!! [Tue Jun 18 23:24:57 2013] [debug] GET /add_news (Mozilla/5.0 (X11; Li +nux x86_64; rv:24.0) Gecko/20130618 Firefox/24.0). [Tue Jun 18 23:24:57 2013] [debug] Routing to a callback. [Tue Jun 18 23:24:57 2013] [debug] 200 OK (0.000952s, 1050.420/s). [Tue Jun 18 23:25:00 2013] [debug] GET /add_news (Mozilla/5.0 (X11; Li +nux x86_64; rv:24.0) Gecko/20130618 Firefox/24.0). [Tue Jun 18 23:25:00 2013] [debug] Routing to a callback. [Tue Jun 18 23:25:00 2013] [debug] 302 Found (0.000915s, 1092.896/s). [Tue Jun 18 23:25:00 2013] [debug] GET /add_news (Mozilla/5.0 (X11; Li +nux x86_64; rv:24.0) Gecko/20130618 Firefox/24.0). [Tue Jun 18 23:25:00 2013] [debug] Routing to a callback. [Tue Jun 18 23:25:00 2013] [debug] 200 OK (0.000518s, 1930.502/s).

I am using the following curl commands.

curl http://127.0.0.1:3000/add_news?offset=10 and curl http://127.0.0.1:3000/add_news?offset=2

How can I make the route call itself?


In reply to Mojolicious and calling current route by onelander

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.