[Dancer-users] Newbie questions: filter fail

Joel Roth joelz at pobox.com
Tue Nov 23 05:46:50 CET 2010


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


More information about the Dancer-users mailing list