From 6af13e7e299fbab4fda3605cb9becd948dad9484 Mon Sep 17 00:00:00 2001 From: "Moritz Grosch (LittleFox)" Date: Mon, 5 Feb 2018 23:37:13 +0100 Subject: [PATCH] Extend perl examples to use more http features (#479) --- examples/perl/hello.pm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/examples/perl/hello.pm b/examples/perl/hello.pm index 0710a26b..680a4f64 100644 --- a/examples/perl/hello.pm +++ b/examples/perl/hello.pm @@ -13,6 +13,24 @@ anything else Dancer2 offers. You can also use Dancer2 and use its DSL. =cut +use utf8; +use strict; +use warnings; + +# Get more helper functions (status and send_as below) +use Dancer2; + return sub { - return 'Hello, ' . (shift->param('name') // 'world'); + my ($request) = @_; + + my ($name) = $request->query_parameters->{'name'} // 'world'; + + # set status code by name + status 'i_m_a_teapot'; + + # send message as JSON + send_as JSON => { + msg => "Hello, $name", + auth => $request->header('Authorization'), # read request header + }; };