How to develop applications for web applications with CGI.pm?

A few years ago I worked a lot with CGI.pm. I appreciate its use for a quick project. Can someone lead me to speed in the current state of development with CGI.pm in the world of "Web 2.0"? What are the best CPAN libraries to use with it? Are there any clean ways to include jQuery, YUI, other CSS libraries, etc., as well as some AJAX. There are, of course, many libraries on CPAN, but what works and what is commonly used?

Are we not doing this yet?

  $ JSCRIPT << EOF;
 ...
 Eof

I understand that people are going to offer Catalyst as an answer. However, many people may have legacy CGI.pm applications that they simply want to improve. Is the best answer really?

+6
perl
source share
9 answers

Personally, I am not a fan of Catalyst (too heavy for my taste) or Mason (mixing code and bad ju-ju HTML), but I use CGI.pm very well for input [1], HTML :: Template for output and CGI :: Ajax to provide the AJAX functionality in which it is invoked.

If you are looking at frameworks, you can also consider CGI :: Application, which is a widely used and lighter alternative to Catalyst / Mason.

[1] I can’t remember the last time I called anything other than $ q-> param or $ q-> cookie from CGI.pm. There are many more tutorials saying that they use their HTML generation functions, but they still mix code and HTML as badly as using documents here, if not worse.

+11
source share

Consider using something more modern, such as Catalyst . It will make your life a lot easier and you won’t have to reinvent the wheel. I understand that this is just a small project, but in my experience many small projects become big in time :)

+4
source share

The web 2.0 applications I worked with usually use client-side JavaScript to request JSON data from the server, then use this data to refresh the page in-place using the DOM.

The JSON module is useful for returning structured data to the browser.

Including JavaScript, HTML, or something in this document is never a good idea, and still hasn't. Instead, use one of the many template modules that can be found in CPAN. For CGI, I would avoid “heavy” modules such as Mason or the Template Toolkit, and use a lighter module for faster startup, such as Text :: Template or Template :: Simple .

+3
source share

Yes, you can write perfect web2.0 web applications WITHOUT using any server-side frameworks in any Perl, Python, Java, etc. WITHOUT using any client-side JavaScript libraries / frameworks. The definition of web 2.0 is some kind of free definition, and I assume that web2.0, you mean Ajax or partial page refresh, then you really need to focus on the following:

  • Be aware of the XmlHttpRequest object.
  • Know how to return a JSON object from server to client.
  • Know how to safely evaluate / parse a JSON object using JavaScript and know how to manipulate the DOM. Also, at least know about innerHTML. InnerHTML is useful sometimes.
  • Know CSS.

Having said that, it is much easier to use some server-side frameworks, but not because web2.0 is required, and it is much easier to use some JavaScript on the client, for example jQuery, mootools, YUI. And you can mix-and-match depending on your needs and your tastes. Most JavaScript provides a wrapper around XmlHttpRequest, so it works in all browsers. No one else writes bare XmlHttpRequest unless you want to show some samples.

+3
source share

It is perfectly possible to write Web 2.0 applications using CGI.pm, but you will have to do this work yourself. From what I saw, the focus in the Perl developer community was to develop successor structures for CGI, rather than creating helper modules that let legacy applications load into modern paradigms. So you are a little different.

How to start, what are you really trying to achieve? Each definition of "Web 2.0" is slightly different.

If you are trying to introduce some modern features (for example, AJAX) for an outdated application, then there is no reason why you need to start.

On the other hand, if you are trying to write something that really looks, feels and works like a modern web application (for example, switching from page loading is an application model), you should probably consider starting from scratch. An attempt to make such a transformation will occur after the fact is more complex than it costs for anything but the simplest applications.

+2
source share

I agree with Adam's answer, you probably want to use Catalyst. Moreover, if you really do not want this, nothing prevents you from using only CGI.pm. The fact is that Catalyst is a collection of packages that make what you want to make Web 2.0 easy. It combines various template engines such as the Template Toolkit or Mason with various ORM interfaces such as DBIx :: Class and Class :: DBI.

Of course, you do not need to use these things to write Web 2.0 applications, this is just a good idea. Part of your question is whether javascript and CSS frameworks such as jQuery, or a prototype of something from server code are needed. They do not do this, you can use them with any request on the server side.

+1
source share

If switching from CGI.pm to Catalyst seems too complicated, maybe something like Squatting might be more appropriate?

Squatting is a web microframe, and I found it ideal for rapid prototyping and for replacing / updating my old CGI scripts.

I recently created a small "web 2.0" application with Squatting using jQuery without any problems. Inside the CPAN distribution, there is an example directory that contains some programs that use jQuery and AJAX, including a very interesting [COMET] ( http://en.wikipedia.org/wiki/Comet_(programming)) example that uses Continuity (which by default squatting down).

NB. If necessary, you can later “hook” your Catalyst application with Squatting :: On :: Catalyst

+1
source share

For new applications, if you don’t find Catalyst to your liking, Dancer is another lightweight structure that you might like. There are also many others, including CGI :: Simple, Mojo / Mojolicious, Squatting ...

Any of these lightweight frameworks can take care of the boring parts of web programming for you and let you keep writing fun parts the way you want.

+1
source share

There is also CGI :: Ajax .

0
source share

All Articles