PerlDancer / PerlDancer/Dancer2

Cannot start Dancer2 when Dancer2::Plugin has Moo attribute

Open
#1,788 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Perl
Stars
604
Forks
288
Avg merge
1d 5h
Merged PRs (30d)
5

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with app.psgi and the simplified Dancer2::Plugin::App example, using the plackup command shown. Start with the Dancer2::Plugin loading path and the lib/App.pm stack-trace location, then verify that an attribute-bearing plugin can load and the example application starts without the Type::Tiny error.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
backend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.