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

Warren Young wyml at etr-usa.com
Mon Aug 31 21:24:55 BST 2015

On Aug 31, 2015, at 2:11 PM, Amelia Ireland <aireland at lbl.gov> 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.

> 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.

More information about the dancer-users mailing list