Acme-CPANModulesBundle-Import-PerlDancerAdvent-2018
    
    
  
  
  
view release on metacpan or search on metacpan
devdata/http_advent.perldancer.org_2018_13 view on Meta::CPAN
    </ul>
</li>
</ul>
</div>
<div id="content">
<div class="pod-document"><h1><a name="the_twelve_days_of_dancer"></a>The Twelve Days of Dancer</h1>
<p>Hello and goodbye, 2018! It seems like we hardly knew you. It's been a few 
years since our last calendar, and while everyone here is busy with other 
projects, we still wanted to give you a mini-advent-calendar this year. 
Welcome to the Twelve Days of Dancer!</p>
<p>This year's calendar features twelve posts that cover a wide range of topics.
We feature several new authors, cover some new ground (for us!) with an
article on accessibility, and even have a crossover post showing how Dancer
can be used with other frameworks.</p>
<p>Without further ado, let's dance!</p>
<h2><a name="state_of_the_dancer"></a>State of the Dancer</h2>
<p>In 2017 and 2018, we saw fewer but more significant updates to Dancer and 
Dancer2. With Dancer (1) being in maintenance mode, updates come only when
significant bugs are found, security vulnerabilities are found, or when a 
change is proposed that greatly improve the lives of Dancer developers. 
devdata/http_advent.perldancer.org_2018_20 view on Meta::CPAN
  ->content_type_like(qr[text/html])
  ->text_is('dl#data dt#hello + dd', 'world');
$t->post_ok('/html' => form => { name => 'grinch' })
  ->status_is(200)
  ->content_type_like(qr[text/html])
  ->text_is('dl#data dt#hello + dd', 'grinch');
done_testing;</pre>
<p>In this year's Mojolicious advent calendar, we've already seen <a href="https://mojolicious.io/blog/2018/12/05/compound-selectors/">some</a> <a href="https://mojolicious.io/blog/2018/12/14/a-practical-example-of-mojo-dom/">great</a> <a href="https...
The point remains however, testing HTML responses with CSS selectors allows you to make your tests targetd in a way that allows you to write more and better tests since you don't have to hack around extracting the bits you want.</p>
<h2><a name="testing_websockets"></a>Testing WebSockets</h2>
<p>Ok so that's great and all, but of course now it comes to the point you've all been waiting for: can you test WebSockets?
As Jason Crome mentioned in his <a href="http://advent.perldancer.org/2018/13">Twelve Days of Dancer</a> "State of Dancer", you can now dance with WebSockets via <a href="https://metacpan.org/pod/Dancer2::Plugin::WebSocket">Dancer2::Plugin::WebSocket...
<p>Well, so far not via the role I showed above.
It might be possible, but it would involve learning deep PSGI magick that I'm not sure I'm smart enough to do; patches welcome obviously :D.</p>
<p>Still I mentioned above that Test::Mojo can test anything it can access via an fully qualified URL, so let's just start up a server and test it!
I'll use the <a href="https://github.com/yanick/Dancer2-Plugin-WebSocket/tree/releases/example">example bundled with the plugin</a> for simplicty.</p>
<pre class="prettyprint">use Mojo::Base -strict;
( run in 0.497 second using v1.01-cache-2.11-cpan-c333fce770f )