[dancer-users] Plugin Adaptor

Rick Leir richard.leir at canadiana.ca
Fri Sep 18 19:52:49 BST 2015


Can you help me with the Plugin Adaptor?

Looking at

https://metacpan.org/source/YANICK/Dancer2-Plugin-Adapter-0.006/t/file-temp.t
it seems as if a Plugin Adaptor test should go like this:

use strict;
use warnings;
use Test::More 0.96 import => ['!pass'];

use Plack::Test;
use HTTP::Request::Common;
    use Data::Printer;

{ # Test app
    package Test::Adapter::fuu::Barr;
    use Dancer2;
    use Dancer2::Plugin::Adapter;

    set show_errors => 0;
    set serializer => "JSON";
    set plugins => {
                    "Adapter" => {
                                capdir => {
                                           class => 'fuu::CAP::Directory',
                                           constructor => 'new'
                                          },
                               },
                   };
    get '/' => sub {
        if ( -d service("capdir") ) {
            return {message => 'Hello World'};
        }
        else {
            return ({message => service});
        }
    };
}
my $test = Plack::Test->create( Test::Adapter::fuu::Barr->to_app );
my $res  = $test->request( GET '/' );
p( $res);

ok( $res->is_success, 'Successful request' );
#like $res->content->{message}, qr/Hello World/i, "Request content correct";
like $res->content, qr/Hello World/i, "Request content correct";

done_testing;
===========================================
exception below:
==================
$ perl -T -Ilib t/004_plugin_adapter_dir.t 2>&1
[Test::Adapter::fuu::Barr:9518] error @2015-09-18 14:38:41> Route
exception: Dancer2::Plugin::Adapter::service() requires a name argument at
lib/Dancer2/Plugin/Adapter.pm line 42. in
/usr/local/share/perl/5.20.1/Dancer2/Core/App.pm l. 1276
HTTP::Response  {
    Parents       HTTP::Message
    public methods (23) : as_string, base, clone, code, current_age, dump,
error_as_HTML, filename, freshness_lifetime, fresh_until, from_psgi,
is_error, is_fresh, is_info, is_redirect, is_success, message, new, parse,
previous, redirects, request, status_line
    private methods (0)
    internals: {
        _content
"{"status":500,"exception":"Dancer2::Plugin::Adapter::service() requires a
name argument at lib/Dancer2/Plugin/Adapter.pm line
42.\n","message":"","title":"Error 500 - Internal Server Error"}",
        _headers   HTTP::Headers,
        _msg       "Internal Server Error",
        _rc        500,
        _request   HTTP::Request
    }
}
not ok 1 - Successful request
#   Failed test 'Successful request'
#   at t/004_plugin_adapter_dir.t line 45.
not ok 2 - Request content correct
#   Failed test 'Request content correct'
#   at t/004_plugin_adapter_dir.t line 47.
#
'{"status":500,"exception":"Dancer2::Plugin::Adapter::service() requires a
name argument at lib/Dancer2/Plugin/Adapter.pm line
42.\n","message":"","title":"Error 500 - Internal Server Error"}'
#     doesn't match '(?^i:Hello World)'
1..2
# Looks like you failed 2 tests of 2.
====================
The exception above is coming from line 47 below
========================
Dancer2/Plugin/Adapter.pm
========================
register service => sub {
  my ( $dsl, $name ) = plugin_args(@_);

  unless ($name) {
     die "Dancer2::Plugin::Adapter::service() requires a name argument";
# line 47
  }

  $conf ||= plugin_setting();

  # ensure service is defined
  my $object_conf = $conf->{$name}
    or die "No configuration for Adapter '$name'";

==============
Dancer2/Plugin.pm  around line 136
===============
sub plugin_setting {
    my $plugin = caller;
    my $dsl    = _get_dsl()
        or croak 'No DSL object found';

    ( my $plugin_name = $plugin ) =~ s/Dancer2::Plugin:://;

    return $dsl->app->config->{'plugins'}->{$plugin_name} ||= {};
}
=================

(ref
  https://metacpan.org/pod/Dancer2::Manual::Testing and
  https://metacpan.org/pod/Plack::Test

http://search.cpan.org/~xsawyerx/Dancer2-0.162000/lib/Dancer2/Manual/Testing.pod
)
-- 
Thanks -- Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150918/fa9e58f3/attachment.html>


More information about the dancer-users mailing list