Acme-CPANModulesBundle-Import-MojoliciousAdvent-2017

 view release on metacpan or  search on metacpan

devdata/https_mojolicious.io_blog_2017_12_02_day-2-the-stash  view on Meta::CPAN

  my $name = $c->stash('name');
  $c->stash(text => "Hello $name");
};
app->start;
</code></pre>

<p>Here we see that <a href="http://mojolicious.org/perldoc/Mojolicious/Guides/Routing#Standard-placeholders">placeholder</a> values get merged into the stash.
We then can use them to render a more personalized response.
If you start the server and request <code>/Joel</code> in your browser you should see an application greeting me, or you can do it with your name.</p>

<p>If you tried to request <code>/</code> however, you would get a 404, not found.
The router doesn&#39;t want to handle this request without a value for the placeholder, so it assumes you wanted some other route to handle it.
While we could define another one for <code>/</code>, as we did before, we can do both at once by bringing back the defaults.</p>

<pre><code>use Mojolicious::Lite;
get &#39;/:name&#39; =&gt; {name =&gt; &#39;🌍 world!&#39;} =&gt; sub {
  my $c = shift;
  my $name = $c-&gt;stash(&#39;name&#39;);
  $c-&gt;stash(text =&gt; &quot;hello $name&quot;);
};
app-&gt;start;



( run in 2.651 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )