Acme-CPANModulesBundle-Import-MojoliciousAdvent-2017

 view release on metacpan or  search on metacpan

devdata/https_mojolicious.io_blog_2017_12_10_day-10-give-the-customer-what-they-want  view on Meta::CPAN

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
      name =&gt; &#39;<span class="hljs-string">Rudolph</span>&#39;,
      description =&gt; &#39;<span class="hljs-string">has a very shiny nose</span>&#39;,
    },
  );
  <span class="hljs-keyword">return</span> <span class="hljs-type">$reindeer</span>{<span class="hljs-type">$name</span>};
};
 
get &#39;<span class="hljs-string">/:name</span>&#39; =&gt; <span class="hljs-keyword">sub </span>{
  <span class="hljs-keyword">my</span> <span class="hljs-type">$c</span> = <span class="hljs-function">shift</span>;
  <span class="hljs-keyword">my</span> <span class="hljs-type">$reindeer</span> = <span class="hljs-type">$c</span>-&gt;<span class="hljs-type">reindeer</span>(<span class="hljs-type">$c</span>-&gt;<span class="hljs-type">stash</span>(&#39;<span clas...
  <span class="hljs-keyword">return</span> <span class="hljs-type">$c</span>-&gt;<span class="hljs-type">reply</span>-&gt;<span class="hljs-type">not_found</span> <span class="hljs-keyword">unless</span> <span class="hljs-type">$reindeer</span>;
 
  <span class="hljs-type">$c</span>-&gt;<span class="hljs-type">respond_to</span>(
    json =&gt; {json =&gt; <span class="hljs-type">$reindeer</span>},
    xml  =&gt; {template =&gt; &#39;<span class="hljs-string">reindeer</span>&#39;, reindeer =&gt; <span class="hljs-type">$reindeer</span>},
    txt  =&gt; {text =&gt; &quot;<span class="hljs-type">$reindeer</span>-&gt;<span class="hljs-string">{name}: </span><span class="hljs-type">$reindeer</span>-&gt;<span class="hljs-string">{description}</span>&quot;},
    any  =&gt; {status =&gt; 406, text =&gt; &#39;<span class="hljs-string">Only json, xml, and txt are supported</span>&#39; },
  );
};
 
<span class="hljs-keyword">use</span> <span class="hljs-function">Test::More</span>;



( run in 0.219 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )