in reply to Re^2: Output should have multiple segments
in thread Output should have multiple segments

Mason has a lot going for it. First of all, it uses Perl, not some new dinky language. Its architecture is sound, it is mature, and there are excellent documents on using it.

When I first looked at ASP a good many years ago, that was my reaction too: mixing the code and data is bad, we should be separating it. It's awesome for just dropping in a value in the middle of a paragraph of HTML, and is really no different from how we interpolate in string literals.

But I see that Mason has a few features so you are not forced to mix it to badly. If you decide to use "interpolation" in the same way as with Perl strings, and stick with pre-computed values in variables, and put real code elsewhere: The init section is solid Perl and computes all the needed values.

For repeating lines, you can put a Perl loop around the HTML. In a specialized template notation that is all you could do, but here you could use any Perl any time. But don't. Stick to foreach loops on a % line.

You can also call Mason components from normal Perl expressions, and are not forced to shift gears back and forth to do some computing, emit a component, and compute some more. You could even simply print ordinary Perl strings to the emitted output.

—John

  • Comment on Re^3: Output should have multiple segments

Replies are listed 'Best First'.
Re^4: Output should have multiple segments
by Herkum (Parson) on Jul 16, 2008 at 05:13 UTC

    Mason is very flexible, the problem is that it is hard to make it follow a consistent structure. Anything you can do in Perl you can do in Mason, and that is the problem. A web page is about presentation. Once you start putting other stuff, like business logic, you are going to make it harder for to maintain and decrease portability with other applications. That is why I say avoid Mason, it is too easy to be lazy!

      That is why I say avoid Mason, it is too easy to be lazy!

      Hehe, that's playing against the "rules", because if you s/Mason/Perl/ in this sentence you will still have a true statement, this being one of the most controversial Perl feature (advocacy wise, at least) ;-)

      Of course, this is just a quick note, it's not my intention to take sides in a possible "mine rocks, yours sucks" flame :))

      --
      altblue.