Perl Question

I am a Perl newbie, and over the course of learning Perl have come up with
a question that I thought someone here could answer effectively:

What advantages does Mason have over CGI.pm?

I am trying to decide how I should divide my time spent learning Perl, and
just kind of came up with this question because I see Perl as being a
language that offers many different possible solutions to any given
problem. Is this just a situation where Mason and CGI.pm are a matter of
personal preference (i.e. you can basically accomplish the same things
with either one), or are there differences between them that makes one
better suited for a particular task than the other one.

What advantages does Mason have over CGI.pm?

Are you asking which you should use for RT work, or are you asking an
off topic question on a high volume mailing list?

However, Mason and CGI.pm are not what you mean to be comparing. Mason
will even run under CGI.pm. I have no idea if you’re asking about the
comparative merits of CGI.pm vs. mod-perl vs. fast-cgi, or if you’re
asking a more general questions about what mason does. Either way,
there are more appropriate forums. google should help in finding them.

seph

I want to customize rt, which is why I’m asking the question…
I basically understand that mason allows you to embed Perl in html. I’m confused however by how cgi.pm seems to almost be the idea of simply generating html using Perl as opposed to Mason allowing you to embed Perl in html. What I want advice on is this:
Since I’m just learning, but would like to customize rt, should I spend any time with cgi.pm or just crack open the mason book and learn that approach.
I’m not asking the wrong forum, because RT is the main reason that I want to learn Perl. I’ve read a couple of Perl books, but just wanted a bit of direction.

…----- Original Message -----
From: seph [seph@directionless.org]
Sent: 06/10/2004 05:16 PM
To: MikeHamilton@clovisusd.k12.ca.us
Cc: rt-users@lists.bestpractical.com
Subject: Re: Perl Question

What advantages does Mason have over CGI.pm?

Are you asking which you should use for RT work, or are you asking an
off topic question on a high volume mailing list?

However, Mason and CGI.pm are not what you mean to be comparing. Mason
will even run under CGI.pm. I have no idea if you’re asking about the
comparative merits of CGI.pm vs. mod-perl vs. fast-cgi, or if you’re
asking a more general questions about what mason does. Either way,
there are more appropriate forums. google should help in finding them.

seph

I want to customize rt, which is why I’m asking the question…

Then You should learn Mason IMHO, since it allows You to reuse more of
the existing infrastructure. Also, Your customizations will be easier
to fit into RT, since it provides mechanisms to replace the existing
implementations by local ones without having to touch the original
files.

Regards,
Harald

I thought of a better way to word my question, and hopefully this will help
someone understand the conceptual hurdle that I have in learning about
this:
What advantage is there to embedding perl in html (I.e. Mason) vs just
generating the web page using raw perl (probably using cgi.pm to generate
the html).
I think my hurdle has to do with the difference between cgi and modperl,
which is why I would like to understand the advantage better. Is that a
better version of the question? I want to know because it would really help
me to figure out how RT works a bit better. I went to the RT training in sf
last year, but didn’t know any Perl at the time and now using RT is making
me want to understand the components that make up RT so that I could write
some customizations for it. Fact is, I doubt that a book would be able to
answer this as well as someone who actually understands RT rather than some
generic Perl guru that would not understand the context of the question. I
hope that my question makes more sense, because the question itself is
bugging me. Is it a matter of programming approach or a matter of the logic
of the pieces that make up the foundation of tools that RT runs on.
I’m not trying to ask a question that should be in a more generic Perl
forum, so please forgive the cloudy nature of my first question. I would
like help understanding the perspective that RT operates from so that I can
make the time that I spend learning Perl more useful.

I thought of a better way to word my question, and hopefully this will help
someone understand the conceptual hurdle that I have in learning about
this:
What advantage is there to embedding perl in html (I.e. Mason) vs just
generating the web page using raw perl (probably using cgi.pm to generate
the html).

The answer, like almost everything, is “it depends on what you want”.

Mason provides a very nice framework for not just generating HTML, but
for reuse of code and design from a site-centric viewpoint. There are a
number of conveniences (things like autohandlers, dhandlers, inheritance)
that are extremely useful when designing sites. Note the emphasis - sites,
not pages.

Other approaches are faster, or stick to a stricter MVC framework (which
you can do in Mason, if you want), or different conveniences.

As far as the difference between embedding Perl in HTML and generating
HTML, in the end, you’re doing the same thing. Different people have
different preferences. I personally really appreciate being able to do
simple switches inline in the HTML:

% (if $logged_in) {
Hello, <% $username %>
% } else {
Please log in
% }

Seems much more natural to me than writing a generator. It is really
purely a matter of preference.

(Actually, I usually do that sort of thing completely inline:
<% $logged_in ? 'Hello, ’ . $username : ‘Please log in’ %>
but some people don’t like that.)

That’s just one example - we do a lot of (non-RT) Mason work, and find
it the best tool for what we do.

If you’re customizing RT, it seems to me to make little sense to bring
in an entirely different toolchain unless you have a really good reason.
You’ll bloat the app, end up writing things that already exist, have
a lot of friction where the customizations rub up against the rest of
the app, and likely have a lot of work every time you the base app.

Anyway, that’s my $.02. HTH.

-j

Jamie Lawrence jal@jal.org
Reality is that which, when you stop believing in it, doesn’t
go away.

  • Philip K. Dick

I want to customize rt, which is why I’m asking the question…

Then you should start by getting a good knowledge of perl. Much of the
RT customization is straight perl, using the existing RT stuff for the
web related stuff. Understanding perl’s objects, pointers, and modules
helps a good deal.

After that I’d spend a short period of time getting a rough feel for
CGI and how web interaction works (like a day). Then either jump into
RT, or spend a bit with mason. RT should be pretty easy, if you’ve
picked up the perl background.

seph

Thanks for the guidance :slight_smile:
Without a good understanding of how RT worked, reading some of the basic
code was a little confusing. This makes much more sense now. Of course, I
should have asked the question a bit better :slight_smile:

I thought of a better way to word my question, and hopefully this will help
someone understand the conceptual hurdle that I have in learning about
this:
What advantage is there to embedding perl in html (I.e. Mason) vs just
generating the web page using raw perl (probably using cgi.pm to generate
the html).
I think my hurdle has to do with the difference between cgi and modperl,

Of course, it depends :slight_smile:

The simple bottom line for RT is, use Mason. RT already does,
and you’re better off fitting in.

As far as cgi and modperl, ‘cgi’ is for creating web pages
as the output of real-time programs, whether in perl or C or shell
or whatever. ‘mod_perl’ is for changing apache’s behavior using
perl, which can include auth/auth, url rewriting, logging,
or anything apache does internally. It so happens that mod_perl
can also run cgi that are written in perl, hence your interest.
But modperl and cgi are not at all the same, they just
happen to overlap in the perl-cgi area.

As far as the straight perl (cgi.pm generation of html to you)
or inside-out (perl inside html, as in Mason or Template::Toolkit),
it’s a matter of style and preference. For really simple
pages, I write straight perl (with print statements, not even CGI.pm)

However, I quickly reach for a templating language when the
page becomes even a little more complicated. This enables me
to use straight perl for database fetches and complicated
assembly of data to display, and use the templating language
for rendering. Of course, rendering can involve some computation
(if X is present, display Y, otherwise Z), so you need some
control, not just substitutions.

If I’m careful to put the “what to display” in perl and the
“how to display” in the template, I find my code much
easier to understand and maintain. So I like both :slight_smile:

bobg

MikeHamilton@clovisusd.k12.ca.us wrote:

I want to customize rt, which is why I’m asking the question…
I basically understand that mason allows you to embed Perl in html. I’m confused however by how cgi.pm seems to almost be the idea of simply generating html using Perl as opposed to Mason allowing you to embed Perl in html. What I want advice on is this:
Since I’m just learning, but would like to customize rt, should I spend any time with cgi.pm or just crack open the mason book and learn that approach.
I’m not asking the wrong forum, because RT is the main reason that I want to learn Perl. I’ve read a couple of Perl books, but just wanted a bit of direction.

	mod_perl vs CGI.

CGI can run any program. it prepare environment for app and exec it,
then send output to user. Even Delphi app can run under CGInterface.

mod_perl is different technology like PHP via CGI vs mod_php.
There is different ways to use it:

  1. Run same CGI scripts under it for speedup(Apache::Registry*). It’s
    that that mod_php provide to PHP lang.
  2. mod_perl give you access to Apache API. CGI in apache implented with
    extension mod_cgi which is content handler. mod_auth is auth handler.
    mod_rewrite is translate uri handler. Now imagine you can write all that
    handlers yourself with perl and has all that power that C developers
    have when write their apache modules.

http://modperl.com:9000/

	Mason.

Mason is group of perl modules which give you framework with own rules,
advantages and disadvantages.

  1. You can run it under CGI environment, mod_perl and FastCGI.
  2. You can mix code with HTML
  3. and many other things like dhandlers, autohandlers…

Main disadvantages:

  1. app run slower even under MP(still more faster then pure CGI) then it
    can run in pure MP environment, it’s price that you should pay for
    portability.

  2. You don’t use apache API directly.

     RT
    

I can split RT into several parts:

  1. DB as backend(MySQL, Pg, Oracle…)

  2. DBIx::SearchBuilder module which is wrapper over DB and exactly this
    module allow you use different DB engines for same app.

  3. RT Core API is collection of classes( /opt/rt3/lib ) which allow you
    operate with RT Objects(Ticket, Queue…)

  4. Front-end based on Mason technology(/opt/rt3/share/html) which uses
    RT API and give you nice WebUI. Also it provides REST interface.

     Good luck. Ruslan.