Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
kimhanse opened this Issue · 2 comments

2 participants

@kimhanse

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';
};
@yanick
Owner

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. :-)

@kimhanse

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 referenced this issue from a commit in kimhanse/Dancer2-Plugin-Cache-CHI
@kimhanse kimhanse Test cache initialization done by check_page_cache 2221204
@kimhanse kimhanse referenced this issue
Closed

Releases #4

@yanick yanick closed this issue from a commit
@yanick grab the right DSL
fixes #5

a the commit.
ac90e81
@yanick yanick closed this in ac90e81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.