Padre::Plugin::Plack

Posted on December 24th, 2009 in Comp, Perl by Patrick

In conjunction with today’s Christmas release of Padre, I’d like to announce my latest Padre plugin: Padre::Plugin::Plack.

As the name suggests, Padre::Plugin::Plack adds Plack awareness to Padre. With the plugin installed, opening *.psgi files causes some special things to happen. PSGI files are really just ordinary Perl files, so Padre does its normal Perl lexing/syntax highlighting magic on them, but the real fun starts with the Plack-specific features that appear in the per-file graphical plackup control panel that shows up. The panel lets you run your web app in a Plack server at the click of a button, view server output, configure plackup options and launch a web browser on the appropriate port.

The great thing about Plack/PSGI is that unlike my previous plugin (Padre::Plugin::WebGUI) which was specific to a single web app (albeit a big one), this plugin can be used for any web app built in a web framework that supports Plack (Catalyst, CGI::Application, HTTP::Engine, etc..). This potential for cross-framework application is one of the motivating factors that makes developing Plack modules (Middleware etc..) so much fun.

The plugin turns on plackup’s “–reload” option by default, which conveniently causes the plack server to reload every time you modify your source files in Padre. This makes for quite a nice, if somewhat minimal “Plack IDE” experience (this is version 0.01 after all).

The plugin integrates all of the Plack example “dot-psgi” files as templates that can be used to create different types of Plack apps straight from the GUI menu.

The pre-populated list of Plack servers and the simple start/stop button makes for a nice way of exploring the Plack server ecosystem. You can use the other panel options to enter a specific port to run on, toggle auto-start mode and pass additional options to plackup (options that start with “–” are passed through to the backend server).

The output panel is similar to the output panel that Padre normally displays when you execute Perl files, except that you get one panel per .psgi file meaning that you can run multiple plack servers simultaneously and independently view their output. The appropriate panel is automatically selected when you click on the corresponding file tab, and running processes are stopped when you close the tab.

It should be really easy to turn Padre::Plugin::Plack into new plugins that involve the same basic ingredients, namely  a file extension and an external command for running those files, with a per-file panel for command options and output. So I encourage anyone who has a similar plugin in mind to steal liberally from Padre::Plugin::Plack (as I did from Padre::Plugin::Catalyst – thanks garu++). Ruby Rack support comes to mind as a trivial example.

Make Padre your domain-specific IDE today :)

Plack helps with Javascript development too

Posted on December 19th, 2009 in Comp, Javascript, Perl by Patrick

Today I was debugging a Javascript bug in ExtJS + AIR, and I wanted to check rendering in another browser. I created a static html file with the minimal javascript test case embedded in it, but then realised that I needed to load in the ExtJS files from somewhere. With other JS libraries you can use freely available CDNs for this sort of thing, but because ExtJS has funky ideas about licensing, this isn’t an option. What I needed was a quick and easy way to serve up the ExtJS files, which were sitting in a folder on my computer, over http. This sort of thing happens frequently with custom code too, when you attempt to create a static (minimal test case) version of a live site.

Plack has a really neat solution to this problem.

Following a tip from day #5 of Miyagawa’s Plack advent calendar, serving up the current directory over http is as simple as this Perl one-liner:


$ plackup -MPlack::App::Directory -e 'Plack::App::Directory->new

Plack::Server::Standalone: Accepting connections at http://0:5000/
$ plackup -MPlack::App::Directory -e ‘Plack::App::Directory->new’Plack::Server::Standalone: Accepting connections at http://0:5000/$ plackup -MPlack::App::Directory -e ‘Plack::App::Directory->new’
Plack::Server::Standalone: Accepting connections at http://0:5000/
# Or if you need the files over port 80:
$ sudo plackup -MPlack::App::Directory -e ‘Plack::App::Directory->new’ -p 80
Plack::Server::Standalone: Accepting connections at http://0:80/

Or if you need the files served over port 80:


$ sudo plackup -MPlack::App::Directory -e 'Plack::App::Directory->new' -p 80

Plack::Server::Standalone: Accepting connections at http://0:80/