[dancer-users] Using Dancer2 as a website framework

sawyer x xsawyerx at gmail.com
Tue Sep 3 16:35:54 BST 2013


On Thu, Aug 29, 2013 at 12:31 PM, Adam Witney <awitney at sgul.ac.uk> wrote:

>
> On 28. 8. 2013 18:56, sawyer x wrote:
>
>>
>>
>> The way I suggest people write their website is by separating the
>> application logic from the web layer. I usually implement an API with
>> routes defined under MyApp/Web.pm. The rest of MyApp/ contains all the
>> application logic that can survive and live without the web layer, if
>> needs be.
>>
>> In your case, writing just the web layer would be very simple. You could
>> then transition it to your use application, written in whatever language
>> you want. If you write it correctly, you could switch from Dancer to a
>> different web framework (whether in Perl or not).
>>
>
> Hi,
>
> I'm interested in how exactly you write this API in the web layer, do you
> happen to have an example of this approach? or know of a project that uses
> it?
>

I can't share any of the examples I have. They aren't open-source.
However, it's really not at all complicated.

Imagine having MyApp.pm that has:
use Moose; # or Moo
has ...
has ...

sub do_something {...}

and then you have MyApp/Web.pm that has:
use Dancer2;
my $app = MyApp->new;

# define routes here
get '/' => sub { $app->do_something(...) };

-----

That way you separate the application logic from the web logic.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20130903/eb7c9525/attachment.htm>


More information about the dancer-users mailing list