choroba has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
If I build a Dancer application by
dancer -a MyApp
there are two tests in MyApp/t/. Running
prove -I lib
in MyApp directory makes the both tests pass.

But, if I edit MyApp/lib/MyApp.pm, changing the second line from

use Dancer ':syntax';
to
use Dancer;
the second test fails:
t/002_index_route.t .. 1/2 # Failed test 'response status is 200 for /' # at t/002_index_route.t line 10. # got: '500' # expected: '200' # Looks like you failed 1 test of 2.
The application still runs ok in a browser, though.

Can someone explain what exactly is ':syntax' for? Is the failing test the intended behaviour or a bug?

Replies are listed 'Best First'.
Re: Failing test in the Dancer application
by kcott (Archbishop) on Apr 22, 2012 at 23:57 UTC

    From the CPAN link you provided, under EXPORTS ... :syntax, you'll see: "This tells Dancer to just export symbols and not set up your app. ..."

    Follow the Source link (at the top of that page) and take a look at the sub import { ... } code. You'll note an early return if you've used :syntax:

    # if :syntax option exists, don't change settings return if $syntax_only;

    If you don't use :syntax, the remaining lines of code will be processed:

    $as_script = 1 if $ENV{PLACK_ENV}; Dancer::GetOpt->process_args() if !$as_script; _init_script_dir($script); Dancer::Config->load;

    I expect one or more of these will be causing your test to fail. I say expect because I haven't seen the code for MyApp.pm and 002_index_route.t.

    -- Ken

Re: Failing test in the Dancer application
by Anonymous Monk on Apr 23, 2012 at 00:10 UTC

    Can someone explain what exactly is ':syntax' for? Is the failing test the intended behaviour or a bug?

    Lol ok :) Compare https://metacpan.org/module/Dancer#syntax to https://metacpan.org/module/Dancer#script

    script loads config while syntax only exports get/true/.... all the dancer functions

    In t/002_index_route.t it says

    # the order is important use MyDancerApp; use Dancer::Test;

    Well, if you remove ':syntax' from your dancer app.pm, then you need to switch the order, in t/002_index_route.t, and the test will pass

    I think there are a number of seriousbasic bugs in there but I'm not sure what they are or which is most important

    • the docs for :syntax are thin on the details, but don't link to all the details ("set up your app" is magic talk)
    • definitely the docs need updating to explain this and the order comment update: well Dancer::Test explains
      Be careful, the module loading order in the example above is very important. Make sure to use "Dancer::Test" after importing the application package otherwise your appdir will be automatically set to "lib" and your test script won't be able to find views, conffiles and other application content.

      This is dumb

    • the template should be updated if the order matterrs, esp since the update works regardless of the options in the .pm
    • the order shouldn't matter , but since it does, a lame comment in a template is inadequate -- Dancer::Test should die/croak when its loaded too late or too early with an error message that explains what you need to do
    • at the very least you should be warned about changing the templates, because magic breaks magically
    • the app should croak if the appdir is wrong
    • the appdir should never be set wrong , app should die if appdir can't be set correctly

      To clarify, the LOL was really directed at the incredulity of always tripping on basic bugs every time I look at popular frameworks (Dancer, Mojolicious ) ...

      Thanks for the solution, understanding and insight. Switching the two lines solved the problem.