<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.hoenzb
        {mso-style-name:hoenzb;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Thanks – that makes sense<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Z<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> dancer-users [mailto:dancer-users-bounces@dancer.pm]
<b>On Behalf Of </b>Maxwell Carey<br>
<b>Sent:</b> 19 March 2015 21:59<br>
<b>To:</b> Perl Dancer users mailing list<br>
<b>Subject:</b> Re: [dancer-users] serialiser scope<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Have you read the Dancer advent calendar article about serializers?
<a href="http://advent.perldancer.org/2014/11">http://advent.perldancer.org/2014/11</a><o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">You can use Plack::Builder to mount two separate apps together, and they can still share sessions:<br>
<br>
$ cat MyApp/lib/MyApp.pm <br>
package MyApp;<br>
use Dancer2;<br>
<br>
our $VERSION = '0.1';<br>
<br>
get '/' => sub {<br>
    session foo => 'bar';<br>
    template 'index';<br>
};<br>
<br>
true;<br>
<br>
$ cat MyApp/lib/MyApp/API.pm <br>
package MyApp::API;<br>
use Dancer2;<br>
<br>
set serializer => 'JSON';<br>
<br>
get '/' => sub {<br>
    my $foo = session('foo') // 'fail';<br>
    return { foo => $foo };<br>
};<br>
<br>
true;<br>
<br>
$ cat MyApp/bin/app.psgi <br>
#!/usr/bin/env perl<br>
<br>
use strict;<br>
use warnings;<br>
use FindBin;<br>
use lib "$FindBin::Bin/../lib";<br>
<br>
use MyApp;<br>
use MyApp::API;<br>
use Plack::Builder;<br>
<br>
builder {<br>
    mount '/'    => MyApp->to_app;<br>
    mount '/api' => MyApp::API->to_app;<br>
};<o:p></o:p></p>
</div>
<p class="MsoNormal">And the test:<br>
<br>
$ cat session_test<br>
#!/usr/bin/env perl<br>
<br>
use strict;<br>
use warnings;<br>
use 5.010;<br>
<br>
use WWW::Mechanize;<br>
<br>
my $mech = WWW::Mechanize->new;<br>
<br>
my $base_url = '<a href="http://localhost:5000/">http://localhost:5000/</a>';<br>
my $api_url = $base_url . 'api/';<br>
<br>
$mech->get($base_url);<br>
$mech->get($api_url);<br>
<br>
say $mech->content(raw => 1);<br>
<br>
$ ./session_test<br>
{"foo":"bar"}<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Thu, Mar 19, 2015 at 6:51 AM, Zahir Lalani <<a href="mailto:ZahirLalani@oliver-marketing.com" target="_blank">ZahirLalani@oliver-marketing.com</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Hi All</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">A little confused about the serialiser scope. I get that in the config file, it will apply to the entire application.
 I have a need to setup template driven routes and ajax routes. So I have a number of route files, and all use the app name to link the routes into one application.  Had assumed that the “set serialiser “ would be active in the current package only (i.e. the
 ajax routes file) but it seems it applies to the application since all routes are linked into the same application.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">I have hunted for clues, but in all honesty I am a little confused as to the solution. I know creating a separate
 app would work, but these routes are part of the same app and need to be centrally controlled in terms of session management etc.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Any advice most appreciated</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#888888"> </span><span style="color:#888888"><o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#888888">Z</span><span style="color:#888888"><o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>