Skip to content

Cannot start Dancer2 when Dancer2::Plugin has Moo attribute #1788

@nicolasfranck

Description

@nicolasfranck

Since 2.1.0 Dancer2 cannot be started anymore,
when one of the Dancer2 plugins has a Moo attribute. It crashes with the following error:

$ plackup app.psgi 
Error while loading /Users/njfranck/git/dancer2-plugin-issue/app.psgi: Can't locate object method "_p2_has" via package "Type::Tiny" at (eval 404) line 23.
Compilation failed in require at lib/App.pm line 6.
BEGIN failed--compilation aborted at lib/App.pm line 6.
Compilation failed in require at /Users/njfranck/git/dancer2-plugin-issue/app.psgi line 6.
BEGIN failed--compilation aborted at /Users/njfranck/git/dancer2-plugin-issue/app.psgi line 6.

These are my source files (simplified for testing reasons):

Dancer2::Plugin::App:

package Dancer2::Plugin::App;

use strict;
use warnings;
use Dancer2::Plugin;

has user_id => (
    is => 'ro',
    default => sub {"nicolas"},
);

sub current_user {
    $_[0]->dsl->var("user");
}

sub load_current_user {
    $_[0]->dsl->var(user => {id => "test"});
}

plugin_keywords(qw(
    current_user
    load_current_user
));

1;

App:

package App;

use strict;
use warnings;
use Dancer2;
use Dancer2::Plugin::App;

hook before => sub {
    load_current_user();
};

get '/' => sub {
    content_type 'text/plain';
    my $current_user = current_user();
    sprintf("Dancer2::VERSION=%s", $Dancer2::VERSION);
};

1;

app.psgi:

#/usr/bin/env perl

use strict;
use warnings;
use lib qw(lib);
use App;

App->to_app;

According to the documentation using Dancer2::Plugin turns
your package into a Moo package, right?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions