William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

Perl’s Mason: A solution for large dynamic websites building

Perl’s Mason: A solution for large dynamic websites building

Perl’s Mason (http://www.masonhq.com/) is a powerful Perl-based web site development and delivery engine. Currently it has 2 versions (in CPAN: version 1 is HTML::Mason, version 2 is Mason).

With the supports of Apache/mod_perl‘s persistent environments, Mason is a powerful, high-performance templating for the web and beyond: it solves the common problems of site development: caching, debugging, templating, maintaining development and production sites, and more. So it is suitable for large, dynamic driven websites. Amazon, Delicious are the users.

From the following example we can see how it works:

1. HTML template file index.mc:
% my $name = "Mason";
Hello world! Welcome to <% $name %>.

2. Mason calls the template file:
use Mason;
my $mason = Mason->new(comp_root => '...');
print $mason->run('/index')->output;

It differs from other template systems: unlike many templating systems, Mason does not attempt to invent an alternate, “easier” syntax for templates. It provides a set of syntax and features specific to template creation, but underneath it is still clearly and proudly recognizable as Perl.

Mason is most often used for generating web pages. It can handle web requests directly via PSGI, or act as the view layer for a web framework such as Catalyst or Dancer.

In Perl, there are many templates systems can be used as presentation layer, such as:

  • Text::Template
  • HTML::Template
  • Template::Toolkit
  • Mason

Among them, Mason is used for building large dynamic websites,
With Mason we can embed Perl code in HTML and construct pages from shared, reusable components.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: