EzDevInfo.com

dancer.js

high-level audio API, designed to make sweet visualizations

How do you stop a perl Dancer/Starman/Plack server?

I started a Dancer/Starman server using:

sudo plackup -s Starman -p 5001 -E deployment --workers=10 -a mywebapp/bin/app.pl

but I'm unsure how I can stop the server. Can someone provide me with a quick way of stopping it and all the workers it has spawned?


Source: (StackOverflow)

Access Dancer Log object?

Normally when using dancer you call, for example

debug 'foo';

and it will log the text. But I want to be able to log stuff in an object that doesn't import the dancer syntax. I'm wondering if there's a way to get dancer to just hand me it's log object (I assume there is one) so that I can call things like debug using an object syntax, e.g.

$logger->debug( 'foo' );

Source: (StackOverflow)

Advertisements

An explanation of the nginx/starman/dancer web stack

I've been doing web-programming for a while now and am quite familiar with the LAMP stack. I've decided to try playing around with the nginx/starman/dancer stack and I'm a bit confused about how to understand, from a high-level, how all the pieces relate to each other. Setting up the stack doesn't seem as straight forward as setting up the LAMP stack, but that's probably because I don't really understand how the pieces relate.

I understand the role nginx is playing - a lightweight webserver/proxy - but I'm confused about how starman relates to pgsi, plack and dancer.

I would appreciate a high-level breakdown of how these pieces relate to each other and why each is necessary (or not necessary) to get the stack setup. Thanks!


Source: (StackOverflow)

Perl dancer and Template Toolkit: Including template within template

I am trying to INCLUDE a template within a template, like so:

parent.tt

  <div class="row-fluid">
    <div class="span3">
    [% INCLUDE my_sidebar]
    </div><!--/span-->
   </div>

my_sidebar.tt exists in same folder as parent.tt (/myapp/views)

I have made the following changes to config.yml: With ABSOLUTE

template: "template_toolkit"
engines:
   template_toolkit:
     encoding:  'utf8'
     start_tag: '[%'
     end_tag:   '%]'
     ABSOLUTE : 1

parent.tt contains:

[% INCLUDE /myapps/views/my_sidebar %]

With RELATIVE

template: "template_toolkit"
engines:
   template_toolkit:
     encoding:  'utf8'
     start_tag: '[%'
     end_tag:   '%]'
     RELATIVE : 1
     INCLUDE_PATH: /myapps/views

parent.tt contains:

[% INCLUDE my_sidebar %]

But in both cases, I get the following error:

core - template - file error - my_sidebar: not found at /.../csm/64-bit/cpan/5.16.1-2012.09/lib/Dancer/Template/Abstract.pm line 90.

Source: (StackOverflow)

Configure Dancer from environment variables?

I'm new to Dancer, but I'm trying to configure it to work within a Docker container. As a result, I need to pick up my database settings from the environment.

In my case, I have DB_PORT_3306_TCP_ADDR, and DB_PORT_3306_TCP_PORT coming from Docker. Unfortunately, the Dancer::Plugin::Database module is erroring before I can change the database to use those variables.

use Dancer ':syntax';
use Dancer::Plugin::Database;

if ($ENV{DB_PORT_3306_TCP}) {## Connected via docker.
    database->({
        driver => 'mysql',
        username => 'username',
        password => 'password',
        host => $ENV{DB_PORT_3306_TCP_ADDR},
        port => $ENV{DB_PORT_3306_TCP_PORT},
        database => $ENV{DB_ENV_MYSQL_DATABASE},
    });
}

So the question is, is there a good way to configure Dancer from environment variables, instead of through static YAML?


Source: (StackOverflow)

Perl Dancer or Node.js for small application [closed]

I am using Perl Dancer to develop an application handling minimal routes and requests.

What is the difference between Perl Dancer (micro web framework) and Node.js ? which ll be better Node.js or Perl Dancer?


Source: (StackOverflow)

How can I split the Dancer error log by day?

I am trying to use dancer and starman for my website. And i am succeed in setting the error log into file. Of course i can run a script to move the error log everyday. But I just want to know whether exits method or cpan module to solve the problem. Thanks~


Source: (StackOverflow)

Using Integrated Windows Authentication in a Perl Dancer App

I am currently building a web app with Perl Dancer. This app requires users to authenticate using my company's Active Directory. To avoid prompting users for their usernames and passwords, I would like to use Integrated Windows Authentication. However, I am having a hard time locating any documentation that explains how to use this type of authentication with Perl--let alone with the Dancer framework. At this point, I am not sure if I'll be deploying this app on Apache or IIS, so something that can work with both would be preferable. Does anyone have any suggestions to help me get started?


Source: (StackOverflow)

Dancer vs Catalyst [Perl Web Frameworks] [closed]

What do you think about both? I began reading a book about Catalyst, and found it pretty complex as compared to Dancer. so now I'm giving Dancer a try, and it looks easier to learn and more "human friendly".


Source: (StackOverflow)

Perl Dancer: Instant response in post

I have a site running Dancer.

In this site, i have a form with one textarea, and foreach line written in this textarea, when the form is submitted via post, i do some action for it. Each line starts a process, and it takes some time ( depending of the line, the process can take about 20 secs, 40 secs, 1 minute... )

The post is something like this:

post '/actions/AddSrv' => sub {  
    my $self = shift;
    my @Results;
    foreach my $dest_addr ( split /\n/, params->{HostsList} ){
        #Here starts the process
        my $Result = start_some_process($dest_addr);
        push @Results, $Result;
        ##Now i have the result of this process execution
    }
    template 'actions/AddSrv.tt', { Results => [ @Results ] }, { layout => 'logged_site' };
};

with this code, I need to wait until all $dest_addr are processed to view in the screen the result of all executions. Exists a way to print inmediatly the result of each process when the call to start_some_process() ends? Now I need to wait until the foreach ends, to return the template

How can I achieve something like this?


Source: (StackOverflow)

perl dancer - "any" method - which actual method called?

Using Perl's Dancer module, if you have an "any" method (which will match get/post/put/delete), how can you determine which actual method the browser used?

#!/usr/bin/perl

use Dancer;

my $instance = someclass->new();

any('/' => sub{
  my $method = ???
  my $params = params();
  return($instance->$method($params));
});  

Source: (StackOverflow)

Perl Dancer after hook

Is there a way in Dancer to execute a code after every request?

I tried with an after hook but it seems that it doesn't execute after a file request... There is a hook called 'after_file_render' which is executed a decent number of times after each request but I am not sure what is its purpose. Is it always called after every request?


Source: (StackOverflow)

How do I properly implement Net::OpenID::Consumer for Google logins and request the user's email?

I've been able to use Net::OpenID::Consumer with success, but when I started requesting the user's email address Google now prompts the user to authorize the sharing of their email address. This happens every single time, regardless of whether the user checks the 'Remember this approval' checkbox. How do I keep Google from prompting the user for approval every time?

Our site's OpenID registration and login paths are the same, otherwise we could only request the email address from Google when the user registers.

I'll try and post enough relevant code (this is a Dancer app).

my $csr = Net::OpenID::Consumer->new(                                                                                                            
    ua => LWP::UserAgent->new(),                                                                                                                 
    consumer_secret => $secret,                                                                                               
);

my $claimed_identity = $csr->claimed_identity('https://www.google.com/accounts/o8/id');

$claimed_identity->set_extension_args(
    "http://openid.net/srv/ax/1.0",
        {
            'mode' => 'fetch_request',
            'type.email' => 'http://axschema.org/contact/email',
            'required'   => 'email',
});

my $check_url = $claimed_identity->check_url(                                                                                                    
        return_to => 'http://my.site.com/openid_landing',                                                                                                                
        trust_root => 'http://my.site.com',                                                                              
        delayed_return => 1,                                                                                                                     
    );

Yahoo doesn't appear to have this problem. I guess this could be an issue on Google's end, but I'm betting it's my code.


Source: (StackOverflow)

perl dancer - how pass additional arguments to method hander subroutines?

Is there a way to pass additional variables to a method handler subroutine? I generally dislike using global variables outside the subroutine's scope. I have things like database connection and class instances which I would like the handlers to have access to, without using globals. Using debug to console, looks like @_ is empty for each handler call.

#!/usr/bin/perl

use strict;

use Dancer;
use Data::Dumper;

set('logger' => 'console');

my $somevar = SomeClass->new();

get('/' => sub{
  debug(Dumper(@_));
  debug($somevar);
  return('hello world');
});

Source: (StackOverflow)

Generate unique random strings

I am writing a very small URL shortener with Dancer. It uses the REST plugin to store a posted URL in a database with a six character string which is used by the user to access the shorted URL.

Now I am a bit unsure about my random string generation method.

sub generate_random_string{
    my $length_of_randomstring = shift; # the length of 
                                        # the random string to generate

    my @chars=('a'..'z','A'..'Z','0'..'9','_');
    my $random_string;
    for(1..$length_of_randomstring){
        # rand @chars will generate a random 
        # number between 0 and scalar @chars
        $random_string.=$chars[rand @chars];
    }

    # Start over if the string is already in the Database
    generate_random_string(6) if database->quick_select('urls', { shortcut => $random_string });

    return $random_string;
}

This generates a six char string and calls the function recursively if the generated string is already in the DB. I know there are 63^6 possible strings but this will take some time if the database gathers more entries. And maybe it will become a nearly infinite recursion, which I want to prevent.

Are there ways to generate unique random strings, which prevent recursion?

Thanks in advance


Source: (StackOverflow)