[dancer-users] About Route Handlers

D Perrett perrettdl at googlemail.com
Fri Apr 3 18:59:56 BST 2015


In perl, the value of the last statement executed in a code block is it's
return value, an explicit return is only needed if you want to exit the
chose block earlier than the last statement. Not sure why your third
example isn't working for you. Have you restarted your dancer server since
you edited the code?

Daniel
On 3 Apr 2015 18:30, "Kadir Beyazlı" <kadirbeyazli at gmail.com> wrote:

> Hi All,
>
> I am novice at Dancer, I am sure my question is very easy for you but I
> decided to ask because I failed at the beginning of my study.
>
> I started reading following manual :
>
> *https://metacpan.org/pod/Dancer2::Manual
> <https://metacpan.org/pod/Dancer2::Manual>*
>
> I installed Dancer2, placked up it and opened web page from localhost.
> Everything is OK until here.
>
> There is following info at manual:
>
> *The code block given to the route handler has to return a string which
> will be used as the content to render to the client.*
> It is clear for following example
>
>
>
>
> *get '/test1/:name' => sub {    return "Hi there " . params->{name};};*
> because it returns a string and when I write *http://localhost:5000/test1/kadir
> <http://localhost:5000/test1/kadir> *to browser I see  *Hi there kadir*
> which is the string I expect to see
>
> But next example is as follow:
>
>
>
>
>
> *get '/test2/:name' => sub {    "Hey ".param('name').", welcome here!";};*
> It does not return anything. Because there is no *return* keyword
> *.*
> Despite this I see   *Hi there kadir  *when I write
> *http://localhost:5000/test2/kadir <http://localhost:5000/test2/kadir>*
> But above red background colored sentence says that it must return a value
> *?*
>
> Next example is stranger
>
>
>
>
>
> *:get '/test3/:name' => sub {    "Hello there, " . defined
> param('name')                    ? param('name')                    :
> "whoever you are!";};*
>
> Again there is no *return* keyword. When I write *http://localhost:5000/test3/kadir
> <http://localhost:5000/test3/kadir> *I see only kadir. But at test2
> example, I saw all words despite there is no return keyword. So what is
> rule?
> *-- *
>
> *Kadir BeyazlıComputer Engineer*
> *GSM : +90 535 821 50 00*
>
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150403/6c8d0233/attachment.html>


More information about the dancer-users mailing list