Hi, I'm totally new to Dancer... but long enough to read all of the docs I could find and browse the list archives for this subject. Looks like just what I want. My first attempt to handle authorization was using a filter. However adding any filter code at all caused my app to fail. For example, the simplified test case below, followed by Dancer's diagnostic output. Thanks for any pointers! package danceapp; use Dancer ':syntax'; use Dancer::Error; our $VERSION = '0.1'; before sub { 1 }; get '/*' => sub { my ($match) = splat; my $content; my $textfile = "$match.txt"; my $fullpath = "$textfile"; if (-r $fullpath ){ template 'training.tt', {content => 'bar', topic => $match, }, {layout => undef }; } else { my $error = Dancer::Error->new( code => 404, message => "No such file: $match", ); Dancer::Response::set($error->render); } }; true; The full error text follows: filter error runtime error An error occured while executing the filter at position : Can't use st +ring ("") as a subroutine ref while "strict refs" in use at (eval 80) + line 11. Stack main in ./danceapp.pl l. 5 Dancer in /home/jroth/perl5/lib/perl5/Dancer.pm l. 105 Dancer in /home/jroth/perl5/lib/perl5/Dancer.pm l. 228 Dancer::Handler::Standalone in /home/jroth/perl5/lib/perl5/Dancer/Hand +ler/Standalone.pm l. 58 Dancer::Handler::Standalone in /home/jroth/perl5/lib/perl5/Dancer/Hand +ler/Standalone.pm l. 54 HTTP::Server::Simple in /usr/share/perl5/HTTP/Server/Simple.pm l. 296 HTTP::Server::Simple in /usr/share/perl5/HTTP/Server/Simple.pm l. 332 HTTP::Server::Simple in /usr/share/perl5/HTTP/Server/Simple.pm l. 427 HTTP::Server::Simple::PSGI in /usr/share/perl5/HTTP/Server/Simple/PSGI +.pm l. 103 HTTP::Server::Simple::PSGI in /usr/share/perl5/HTTP/Server/Simple/PSGI +.pm l. 103 Dancer::Handler::Standalone in /home/jroth/perl5/lib/perl5/Dancer/Hand +ler/Standalone.pm l. 39 Dancer::Handler in /home/jroth/perl5/lib/perl5/Dancer/Handler.pm l. 64 Dancer::Handler in /home/jroth/perl5/lib/perl5/Dancer/Handler.pm l. 65 Dancer::Renderer in /home/jroth/perl5/lib/perl5/Dancer/Renderer.pm l. +24 Dancer::Renderer in /home/jroth/perl5/lib/perl5/Dancer/Renderer.pm l. +98 Dancer::Route::Registry in (eval 80) l. 17 Dancer::Error in /home/jroth/perl5/lib/perl5/Dancer/Error.pm l. 23 Dancer::Error in /home/jroth/perl5/lib/perl5/Dancer/Error.pm l. 208 Settings { engines => {}, import_warnings => 1, mime_types => {}, appname => 'danceapp', views => '/oldroot/home/jroth/build/chi2app/views', layout => 'main', session => 'YAML', public => '/oldroot/home/jroth/build/chi2app/public', confdir => '/oldroot/home/jroth/build/chi2app', show_errors => '1', session_dir => '/oldroot/home/jroth/build/chi2app/sessions', server => '0.0.0.0', log => 'debug', daemon => 0, logger => 'file', warnings => '1', template => 'simple', access_log => 1, appdir => '/oldroot/home/jroth/build/chi2app', charset => '', port => '3000', environment => 'development', content_type => 'text/html', apphandler => 'Standalone', auto_reload => '1' } Session { id => '977589889414368076057528273425511622' } Environment $VAR1 = { SCRIPT_NAME => '', SERVER_NAME => '0.0.0.0', 'psgi.multiprocess' => 0, HTTP_ACCEPT_ENCODING => 'gzip,deflate', PATH_INFO => '/hello', HTTP_CONNECTION => 'keep-alive', CONTENT_LENGTH => undef, REQUEST_METHOD => 'GET', HTTP_ACCEPT => 'text/html,application/xhtml+xml,application/xml;q=0 +.9,*/*;q=0.8', 'psgi.multithread' => 0, HTTP_ACCEPT_CHARSET => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', QUERY_STRING => '', HTTP_USER_AGENT => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1. +9.1.13) Gecko/20100916 Iceweasel/3.5.13 (like Firefox/3.5.13)', SERVER_PORT => '3000', HTTP_COOKIE => 'dancer.session=977589889414368076057528273425511622 +', HTTP_ACCEPT_LANGUAGE => 'en-us,en;q=0.5', REMOTE_ADDR => '127.0.0.1', CONTENT_TYPE => undef, HTTP_KEEP_ALIVE => '300', SERVER_PROTOCOL => 'HTTP/1.1', 'psgi.streaming' => 1, 'psgi.errors' => *::STDERR, REQUEST_URI => '/hello', 'psgi.version' => [ 1, 1 ], 'psgi.nonblocking' => 0, 'psgix.io' => bless( \*Symbol::GEN2, 'FileHandle' ), 'psgi.url_scheme' => 'http', 'psgi.run_once' => 0, HTTP_HOST => '127.0.0.1:3000', 'psgi.input' => do{my $o} }; $VAR1->{'psgi.input'} = $VAR1->{'psgix.io'}; -- Joel Roth -- Joel Roth
Hi Joel. I tried to recreate your error but couldn't. Are you using the latest Dancer? (1.2000) Also, there is a community plugin to handle authorization; you might want to check it out: http://search.cpan.org/perldoc?Dancer::Plugin::Authorize S.
On Tue, Nov 23, 2010 at 10:17:41AM +0200, sawyer x wrote:
Hi Joel.
I tried to recreate your error but couldn't.
Are you using the latest Dancer? (1.2000)
Thanks, Sawyer. I didn't know a new Dancer was out. I just installed it... fixes the filter error
Also, there is a community plugin to handle authorization; you might want to check it out: http://search.cpan.org/perldoc?Dancer::Plugin::Authorize
I'd like to try it however, when I install, I get an error in 002_isa.t Any suggestions would be welcome. :-) Joel PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/001_load.t .. ok Use of uninitialized value $_[0] in join or string at /usr/lib/perl5/File/Spec/Unix.pm line 86, <DATA> line 37. session_dir /sessions cannot be created at /home/jroth/perl5/lib/perl5/Dancer/Session.pm line 16 # Looks like you planned 22 tests but ran 2. # Looks like your test exited with 13 just after 2. t/002_isa.t ... Dubious, test returned 13 (wstat 3328, 0xd00) Failed 20/22 subtests Use of uninitialized value $_[0] in join or string at /usr/lib/perl5/File/Spec/Unix.pm line 86, <DATA> line 37. session_dir /sessions cannot be created at /home/jroth/perl5/lib/perl5/Dancer/Session.pm line 16 # Looks like you planned 16 tests but ran 2. # Looks like your test exited with 13 just after 2. t/003_can.t ... Dubious, test returned 13 (wstat 3328, 0xd00) Failed 14/16 subtests Test Summary Report ------------------- t/002_isa.t (Wstat: 3328 Tests: 2 Failed: 0) Non-zero exit status: 13 Parse errors: Bad plan. You planned 22 tests but ran 2. t/003_can.t (Wstat: 3328 Tests: 2 Failed: 0) Non-zero exit status: 13 Parse errors: Bad plan. You planned 16 tests but ran 2. Files=3, Tests=6, 2 wallclock secs ( 0.04 usr 0.03 sys + 1.08 cusr 0.15 csys = 1.30 CPU) Result: FAIL Failed 2/3 test programs. 0/6 subtests failed. make: *** [test_dynamic] Error 13 -> FAIL Installing Dancer::Plugin::Authorize failed. See /home/jroth/.cpanm/build.log for details.
S.
-- Joel Roth
On Tue, Nov 23, 2010 at 3:49 PM, Joel Roth <joelz@pobox.com> wrote:
I didn't know a new Dancer was out. I just installed it... fixes the filter error
Glad to hear it!
Any suggestions would be welcome. :-)
There is a known issue that is already fixed in the source (but not released to CPAN yet) of a race condition in engine triggers. This affects Dancer::Session::Cookie, for example. This might be what you're experiencing. I would really appreciate it if you could try and install the latest source (from Github) and see if it resolves your problem. If not, I sure would like to dwelve into it and fix it. Sawyer.
participants (2)
-
Joel Roth -
sawyer x