#!/usr/bin/env perl # This script demonstrates various getters of the Request object # of Not Even A Framework use strict; use warnings; use MVC::Neaf; # Now to the NEAF itself: set common default values neaf view => 'TT02' => 'TT'; neaf default => { -view => 'TT02', file => 'example/02 NEAF '.MVC::Neaf->VERSION }, path => '/02'; # So far we have to specify \*DATA manually, no magic yet neaf->load_resources( \*DATA ); # Sic! get+post '/02/request' => sub { my $req = shift; if (!$req->postfix) { # This actually dies but with a special-case exception # that Neaf converts into a proper redirect $req->redirect( $req->prefix . "/and/beyond" ); }; # Just return the data # Override the -view if user wants it return { title => 'Taking apart the request object', header_in => $req->header_in->as_string, -view => $req->param(as_json => '1') ? 'JS' : 'TT02', map { $_ => $req->$_ } qw( scheme hostname port method http_version path prefix postfix referer user_agent client_ip ), }; }, ( # This may also be written as 'default => { -template => ... }' # generating an overridable default value for this controller only -template => "main.html", # This is a nerdy cousin of /02/request/:param_name # - smarter, but less pretty path_info_regex => '.*', # This line is just for information # see perl --list description => 'Taking apart the request object', ); # Do good things... and RUN!!! neaf->run; __DATA__ @@ main.html view=TT02 [% title | html %] - [% file | html %]

[% title | html %]

The request

Hover over dotted elements to see the relevant method
[% scheme | html %] :// [% hostname | html %] : [% port | html %] [% prefix | html %] / [% postfix | html %]

Repeat

How web-server saw it

[% method | html %] [% path | html %] HTTP/[% http_version | html %]
[% header_in | html %]

The client

IP: [% client_ip | html %]
Referer: [% referer | html %]
User-agent: [% user_agent | html %]