[dancer-users] Migrating CGI.pm-based code to Dancer2

Amelia Ireland aireland at lbl.gov
Mon Aug 31 22:47:16 BST 2015


Hi Warren,

Thank you for your response!

*Warren Young* wyml at etr-usa.com
<dancer-users%40dancer.pm?Subject=Re%3A%20%5Bdancer-users%5D%20Migrating%20CGI.pm-based%20code%20to%20Dancer2&In-Reply-To=%3CFA02293B-5F0E-4ADA-ABDA-DC3861003948%40etr-usa.com%3E>
 wrote:

> On Aug 31, 2015, at 2:11 PM, Amelia Ireland <aireland at lbl.gov
> <http://lists.preshweb.co.uk/mailman/listinfo/dancer-users>> wrote:
> >
> >
> * 1) The old code is written in a "print as you go" form. * When I ran
> into the same situation in my code base, I handled it like this:
> my $html = “SOme stuff…”;
> $html .= “More stuff…”;
> …repeat until done :) …
> return $html;
> The tricky bit comes in translating things like this:
> print “Some “, $rather, “ complicated “, code();
> You either end up replacing all the commas with dots or:
> $html .= sprintf “Some “, …etc.
>

I'm doing that on a small scale where possible, but unfortunately the size
and unfamiliarity of the codebase (I've only been working with it a couple
of months) make this a daunting prospect. :-(  Capturing STDOUT feels like
a dirty solution--I'd much sooner the app returned data that could be used
to populate templates--but it's really the only viable option at the moment.

>
> * 2) I'm converting the PSGI env into a CGI object using CGI::PSGI; apart
> from HTTP headers, is there anything else I need to take care of? * I
> wouldn’t keep trying to hold onto CGI. Dancer’s always-on route-based
> processing method is quite different from CGI’s model.
> Trying to program Dancer in a CGI-like fashion might make some things a
> bit quicker to translate, but I think you’ll eat that savings up in areas
> that don’t map easily, and in difficulty of understanding the final version
> as it keeps jumping between the CGI and Dancer abstractions.


I'd love to dispatch the CGI-based code elsewhere, but it's a big codebase
and the cgi-based code is in production use, so my changes have to maintain
compatibility with the existing cgi scripts. New code is written in the
Dancer2 paradigm and the old code has a Dancer2 wrapper that handles
authentication, sessions, etc. I'm hoping to convert my coworkers to
Dancer2 once they see how neat and easy it is in comparison to CGI.pm...

Amelia.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150831/3df64a94/attachment.html>


More information about the dancer-users mailing list