1) I don't know of an easy way to have each page as its own .pl, sorry.
2) sessions are pretty easy, as long as you dont mind either always
starting it, or never starting it, based on url.  There is no start session
in the middle of processing.
3) php is a bit confused.  GET and POST are methods, which you can get in
plack with $req->method.  query params are availble with
$req->parameters->{'q'}.  Most of the server stuff is available to,
path_info for example is $req->path_info.
4) http redirect is as simple as returning a 302 header, which you can do.
5) uh... dunno ... probably.  I've seen dancer/mojo do this, but not sure
how.

You dont need dancer/mojo, you can write using straight plack, that's how I
do it.

my standard template would be something like:


#!/usr/bin/perl

use common::sense;
use Plack::Builder;
use Plack::Request;
use Plack::App::File;
use Plack::Session::Store::File;
use Template;

my %cfg = loadconfig();
my $tt = Template->new( {INCLUDE_PATH => 'templates'} );

my %funcs = (
    'main' => \&doIndex,
    'login' => \&doLogin,
    'q' => \&doSearch,
);

my $app = sub {
    my $env = shift; # PSGI env
    my $req = Plack::Request->new($env);
    if (! $req->session) {
        return [ 404, [ 'Content-Type' => 'text/html; charset=utf-8' ], [
'404 session not found' ] ];
    }
    $req->session->{counter}++;
    if (not defined $req->session->{auth})
    {
        $req->session->{auth} = 0;
    };

    my $uri = lc($req->path_info);
    $uri =~ s!^/!!o;     # Remove the first slash
    if (!$uri)
    {
        $uri = 'main';
    }
    #warn("uri = [$uri]");

    my @args = split(/\//, $uri);
    $req->env->{args} = \@args;

    my $proc = $funcs{$args[0]};
    if ($proc) {
        return $proc->($req);
    } else {
        return [ 404, [ 'Content-Type' => 'text/html; charset=utf-8' ], [
'404 not found' ] ];
    }
};

builder {
    mount "/static" => builder {
        enable 'ConditionalGET';
        enable 'ETag',
            file_etag => [qw/inode mtime size/],
            ;

        enable 'ContentLength';
        Plack::App::File->new(root => "static")->to_app;
    };
    mount "/" => builder {
        enable 'Session',
            store => Plack::Session::Store::File->new(
                    dir => 'session'
                );

        $app;
    };
};



On Tue, Aug 16, 2016 at 1:40 PM, ivo welch <ivo...@gmail.com> wrote:

>
> I am thinking about writing a new web program in PSGI/Plack.  I purchased
> the 24-chapter book, but it seems geared towards porting over existing
> apps, not as a starter tutorial.
>
> as I was looking for more info, I noticed the following is dead on the
> plack webpage:
>
>
> PlebGUI: WebGUI meets Plack
> <http://blog.patspam.com/2009/plebgui-webgui-meets-plack>
> Patrick Donelan writes a good introduction for PSGI and Plack from the web
> application developers point of view.
>
>
> but did not see an email for the maintainer.
> nice starters are in http://search.cpan.org/~leejo/
> CGI-Alternatives-0.14/lib/CGI/Alternatives.pm and
> http://savage.net.au/Perl/html/plack.for.beginners.html .
>
> so I really need basic tutorial examples / documentation for a new app.
>  specifically, I need
>
>    - hello world (documentation already exists).  I like the simplicity
>    of keeping each webpage in its own .pl file.  Less enthused by mojo like
>    approach of one big dispatch app.  but I could live with it.   is one
>    dispatch app required for psgi/plack (http://advent.plackperl.org/
>    2009/12/day-12-maps-multiple-apps-with-mount-and-urlmap.html
>    
> <http://advent.plackperl.org/2009/12/day-12-maps-multiple-apps-with-mount-and-urlmap.html>
>    )?
>    - session management (aka CGI:Session) -- aka php $_SESSION
>    - GET, POST, SERVER read access -- aka php $_GET $_POST $_SERVER
>    - http redirect -- aka php header("Location: /elsewhere/file.thml");
>    - CGI::Carp fatalstobrowser  -- aka php default
>
> I have been using Text::Template for a while, and it seems fine.  but it
> could be easily switched.
>
> that's it.
>
> probably 50 lines of code.  would it be possible for someone in the know
> to post here and on the plack/psgi website, too?
>
> does psgi need/have an application skeleton generator, like
> Mojolicious::Command::generate::app
> <http://mojolicious.org/perldoc/Mojolicious/Command/generate/app>?
>
>
> help?
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "psgi-plack" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to psgi-plack+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"psgi-plack" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to psgi-plack+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to