Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Hook error: No DSL object found at lib/Dancer2/Plugin/Cache/CHI.pm line 67. #5

Closed
kimhanse opened this Issue Jun 19, 2014 · 2 comments

Comments

Projects
None yet
2 participants
Contributor

kimhanse commented Jun 19, 2014

I am not sure if this is a problem with this plugin or a general Dancer2 issue.

When trying to rewrite the honor-no-cache.t test from Dancer2::Test to Plack::Test I encountered the following error. I have encountered the same error in the web app I am writing, that was what lead me to looking at the tests for Dancer2::Plugin::Cache::CHI.

The error is:

galley@mich:~/Dancer2-Plugin-Cache-CHI$ perl -I lib/ t/simple.t
1..2
ok 1 - got app
not ok 2 - Simple GET
#   Failed test 'Simple GET'
#   at t/simple.t line 26.
#          got: 'Internal Server Error
#
# Exception caught in 'core.app.before_request' filter: Hook error: No DSL object found at lib/Dancer2/Plugin/Cache/CHI.pm line 67.
#  at /home/galley/perl5/perlbrew/perls/stable/lib/site_perl/5.20.0/Dancer2/Core/App.pm line 653.
#  at /home/galley/perl5/perlbrew/perls/stable/lib/site_perl/5.20.0/Dancer2/Core/Role/Hookable.pm line 141.
# '
#     expected: '42'
# Looks like you failed 1 test of 2.
galley@mich:~/Dancer2-Plugin-Cache-CHI$

It is generated by this test:

use strict;
use warnings;

use Test::More tests => 2;
use Plack::Test;
use HTTP::Request::Common;

{
    package TestApp;

    use Dancer2;
    use Dancer2::Plugin::Cache::CHI;

    check_page_cache;

    get '/test' => sub {
        return 42;
    };
}

my $app = Dancer2->runner->psgi_app;
is ref $app, 'CODE', 'got app';

test_psgi $app, sub {
    my $cb  = shift;
    is $cb->(GET '/test')->content, 42, 'simple GET';
};
Owner

yanick commented Jun 21, 2014

The good news is that I'm able to reproduce the problem. It seems that a few things changed under the hood. I'll try to fix that as soon as possible. But as I'm leaving for YAPC tomorrow morning, there might be a delay. Or the long airport hours might help, who knows. :-)

Contributor

kimhanse commented Jun 22, 2014

I think that the problem is that the hook is called from a hook. This happens because the cache is created by the hook made in check_page_cache, if I just forces the cache to be created before the hook is made it all works. The hack I did in order to test this was:

diff --git a/lib/Dancer2/Plugin/Cache/CHI.pm b/lib/Dancer2/Plugin/Cache/CHI.pm
index b7e77b6..8daab10 100644
--- a/lib/Dancer2/Plugin/Cache/CHI.pm
+++ b/lib/Dancer2/Plugin/Cache/CHI.pm
@@ -84,7 +84,7 @@ sub _create_cache {

 register check_page_cache => sub {
     my $dsl = shift;
-
+cache();
     my $hook = sub {
         my $context = shift;

@kimhanse kimhanse added a commit to kimhanse/Dancer2-Plugin-Cache-CHI that referenced this issue Jun 28, 2014

@kimhanse kimhanse Test cache initialization done by check_page_cache 2221204

@kimhanse kimhanse referenced this issue Jun 28, 2014

Closed

Releases #4

@yanick yanick closed this in ac90e81 Jun 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment