A Django site.
October 8, 2008

Hans Fugal
no nic
The Fugue :
» autotools

I've been known to knock autotools (autoconf and automake and friends), but let it not be forgotten that I have also been known to say that alternative pickings are pretty slim.

Part of the problem with autotools is that it's easy to make an unmaintainable and unusable mess, and one that is essentially opaque to the uninitiated.

But, on the other hand, it's equally easy to use autotools in a sane way which is just as easy or easier than writing makefiles and whatnot by hand. Once you get over the initial learning curve. That has been a big caveat. I've climbed that curve a few times and it goes in one ear and out the other.

Well, a friend pointed out an excellent tutorial on autotools which demystifies autotools. It also makes a good reference for next week when you've forgotten everything.

If you're writing code to distribute, you should consider using autotools (and doing so sanely), and this is a good starting point. But that's not the only reason to check it out. You may just be curious, or you may wish to learn how this works so you can contribute patches and bring sanity to your favorite project's build system.

But whatever you do, never ever just copy someone else's autotools configuration into yours and apply "shotgun debugging" to shoehorn it into your project. That is the wrong approach and the primary cause of so many broken autotools setups.

July 28, 2008

Doran Barton
fozzmoo
Fozzolog
» Perl Basics: Web templating

It doesn't matter what language you do your server-side web development in, presentation templates just make so much sense. Here are some reasons why:

  • Templates (usually) let you re-use commonly used blocks of code.
  • Templates (usually) make it easy (or easier) for a web designer (e.g. not a developer) to work on the presentation layout of your application.
  • Templates allow you to separate presentation from business logic and will help you separate them in how you think of your application as well.

By templates, I mean files that contain HTML data along with some special coded method of interpolating dynamic data into the HTML.

By this definition, PHP and ASP code are template languages themselves. That's one of the more substantial reasons I've come to dislike these languages! You'll come to understand as you read more below.

Here's a very simple template example:


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <title>$TITLE</title>
    </head>
    <body>
        <h1>Welcome to the $SITE_NAME website!</h1>
    </body>
</html>

The above example uses the syntax defined by the CGI::FastTemplate Perl module. I used this module for a couple of projects in 2000 or so and while it does make it easy to design a page's look and feel around the dynamic content your web application is going to drop into the page, it works best when your content doesn't need to be nested inside HTML. For example, dynamics data in a table does not work well with CGI::FastTemplate. Neither do lists of data.

Some templating systems, like CGI::FastTemplate to some extent, can handicap you too much. Others, like HTML::Embperl or ePerl, in my opinion, provide too much capability at the template level.

You don't want to be able to write your entire application in a template. You might as well be writing your application in PHP, JSP, or ASP (or Apache::ASP).

I think a templating system should provide you with just enough logic so that you can affect how data is presented and not much more logic than that. I'm not alone in thinking these things. See Wikipedia topics: Web template system, Model-view-controller, and Separation of concerns.

So, as a result of study of templating systems for Perl, I recommend Template (Template Toolkit for Perl).

Note: Template Toolkit does allow some things I don't think have any place in templates, but it doesn't do so by default. You have to make a conscious choice to do those things, read the documentation, etc. and that should (hopefully) discourage you from doing so.

How to use Template Toolkit

Let's take a look at how Template Toolkit would be used to mimic the CGI::FastTemplate example above.


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <title>[% title %]</title>
    </head>
    <body>
        <h1>Welcome to the [% site_name %] website!</h1>
    </body>
</html>

It's not a whole lot different, is it? And, actually, it's a little more typing to key in those beginning and ending brackets instead of just a preceding dollar sign.

Now, here's an example of how this template file (we'll call it page1.tt) would be used in Perl code, say, in a CGI script.


#!/usr/bin/perl

use CGI qw/:standard/;
use Template;

my $q = CGI;
my $tt = Template->new({
    INCLUDE_PATH    =>  '/var/www/templates/'});

my $vars = {};

$vars->{'title'} = 'Joe Schmoe Shoe Repair - Home';
$vars->{'site_name'} = 'Joe Schmoe Shoe Repair';

print $q->header('text/html');
print $tt->process('page1.tt', $vars) || 
    die $tt->error();

Great! Now we know Template is just as good as CGI::FastTemplate! What else can it do?!

Wrapping an application

One thing I often do with Template Toolkit is use it to wrap applications so that every page has the same look and feel. You do this by defining a wrapper template in the hash reference you pass to the Template constructor:


my $tt = Template->new({
    INCLUDE_PATH    =>  '/var/www/templates/',
    WRAPPER         =>  'sitewrapper.tt', });

Now every page generated by the process() function will include the contents of sitewrapper.tt around it.

The wrapper template needs to contain a special template directive in it: [% content %]. This is where the contents of your specified templates are placed.

Here is an example of a wrapper template:


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <title>[% template.title %]</title>
        <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
        <div class="sidebar">[% INCLUDE sidebar.tt %]</div>
        <div class="body">[% content %]</div>
        <div class="footer">[% INCLUDE footer.tt %]</div>
    </body>
</html>

Notice the use of the [% content %] directive in the wrapper template.

There are a couple other interesting uses of Template Toolkit directives in this example, notably the INCLUDE directive (for inserting the parsed output of other templates) and a special directive within the HTML title tags.

The [% template.title %] directive should make sense once we see how a normal template might look when using a wrapper:


    [% META title = "Contact us" %]
    <h1>Contacting Joe Schmoe Shoe Repair!</h1>
    <p>See the list below for our telephone numbers:</p>
    <ul>
    [% FOREACH phone = phone_numbers %]
        <li>[% phone.name %]: [% phone.number %]</li>
    [% END %]
    

The META directive let's us pass data into the wrapper template.

Flow control

The above template example also introduces to one of the reasons I love Template Toolkit: flow control. In this case, a for-each loop. The variable phone_numbers could be a list of hashes we get from a database and pass to the template. Each hash contains a name-value pair named name and one named number. The FOREACH directive allows us to iterate through the phone_numbers list and assign a reference the current hash to a variable we've named phone. Inside the loop, we can reference the individual name-value pairs by name.

This is only one of the flow control structures Template Toolkit offers. There are also IF-THEN-ELSIF-ELSE structures, CASE/SWITCH structures, and WHILE loops.

These should give you just a taste of what Template Toolkit can do. With the Template Perl module installed on your system, you get all the documentation you could hope for as POD and man files. The Template Toolkit website also has all this documentation online as well.

Below is a bit of a more complex template I created years ago for the utahisps.com website.


      <h3>[% company.name %]</h3>
      <table cellpadding="6">
        <tr>
          <td>Services</td>
          <td>
                [% has_services = 0 %]
                [% FOREACH service_name = services.keys %]
                  [% IF services.$service_name %]
                    <a href="/isp/[% company.company_id %]/[% service_name %]">
                    [ % service_name %]</a><br/>
                    [% has_services = 1 %]
                  [% END %]
                [% END %]
                [% IF has_services == 0 %]
                  N/A
                [% END %]
                  <!-- None listed -->

              </td>
            </tr>
        <tr>
          <td>Address</td>
          <td>
            [% company.addr1 %]<br/>
        [% IF company.addr2.length %]
        [% company.addr2 %]<br/>
        [% END %]
        [% company.city %], [% company.state %] [% company.zip %]
          </td>
        </tr>
        <tr>
          <td>Phones</td>
          <td>
            [% IF company.phone1.length %]
                [% company.phone1 %] ([% company.phone1_desc %])
        [% END %]
            [% IF company.phone2.length %]
        <br/>
                [% company.phone2 %] ([% company.phone2_desc %])
        [% END %]
          </td>
        </tr>
        [% IF company.fax.length %]
        <tr>
          <td>Fax</td>
          <td>[% company.fax %]</td>
            </tr>
            [% END %]
            <tr>
              <td>Website</td>
          <td>< <a href="[% company.www_url %]" 
          target="_new">[% company.www_url %]
          </a> ></td>
            </tr>
        [% IF company.info_email.length %]
        <tr>
          <td>Info E-mail</td>
              <td>< <a href="mailto:[% company.info_email %]"
              target="_new">
              [% company.info_email %]</a> ></td>
            </tr>
            [% END %]
        <tr>
          <td>Payment</td>
              <td>
                [% IF company.credit_cards.length %]
                  [% company.credit_cards %]
                [% ELSE %]
                  Cash/check only
                [% END %]
            </tr>
        [% IF company.oper_since %]
        <tr>
          <td>Oper since</td>
              <td>[% company.oper_since %]</td>
            </tr>
            [% END %]

        <tr>
              <td><a href="http://www.angio.net/rep/" 
              target="_new">Utah
              REP</a><br/>member</td>  
              <td>[% IF company.ut_rep %]Yes[% ELSE %]No[% END %]</td>
            </tr>
            
        [% IF company.os.length %]
        <tr>
          <td>Primary OS</td>
              <td>[% company.os %]</td>
            </tr>
            [% END %]

        [% IF company.upstreams %]
        <tr>
          <td>Upstream feeds</td>
              <td>[% company.upstreams %]</td>
            </tr>
            [% END %]


        [% IF company.notes.length %]
        <tr>
          <td>Notes</td> 
              <td><tt>[% company.notes %]</tt></td>
            </tr>
            [% END %]
     </table>

September 14, 2007
» Learn python with my slides, a cheatsheet, me, or a simple game

I gave my abbreviated "Intro to Python Tutorial" class last night at Utah Python Users Group. There was also a nice intro to django by Seth House and a short discussion of "Python in the Industry" by Byron Clark. So since Duncan asked for some slide


Phil Windley
pjw
Phil Windley's Technometria
» SOA Governance Tutorial

I'm going to be doing a day-long tutorial on SOA governance at the InfoWorld SOA Executive Forum in New York on November 8th. If you register before October 7th, it's $695. After that it's $795 until November 5th. Then the price goes up to $895. Here's the details:

Counterintuitive as it may seem, SOA requires more organizational discipline than previous development models. Your intuition might tell you that flexibility results from less rules, not more, but that's not the case.

Standardization provides the underpinnings for SOA across an organization. To prevent IT from being overwhelmed by this new complexity, the industry has created a new classes of software, registries, repositories, and runtime management systems, that help keep all the rules straight. But creating an SOA for an enterprise demands more than using SOA-based tools -- it requires that IT organizations make serious choices about design, which result in design rules.

This tutorial will:

  • Introduce SOA governance and effective governance models
  • Discuss how to put a governance processes in place
  • Talk about enablers and detriments to effective governance
  • Describe policies and procedures you should put in place now
  • Show you how to create an interoperability framework for your organization
  • Teach you how to build and use reference architectures
  • Describe, evaluate, and compare the tools available to manage SOA governance artifacts

This is a detailed outline:

Governance Models - One of the most important questions to answer is "How does my organization make decisions?" We're after loose coupling and that requires a way for making rules and ensuring that they're followed. Consequently, its important to understand what works--and what doesn't. Governance isn't something that happens once, it's an ongoing process. The governance lifecycle defines the process and provides a timeline. There are some things to watch out for--stumbling blocks that will make it hard to get going until you've moved the out of the way.

SOA Maturity Evaluation - Good governance depends on understanding your processes and where they can be improved and where they are simply incompatible with the loosely coupled organization you want to build. Process evaluation gives you the opportunity to reengineer how your organization gets things done by finding the gaps between where you are and where you want to be and then filling those gaps with best practices. Data architecture is equally important. If you can't find where your data is or if the same kinds of data is stored, formatted, and understood differently in different repositories, you can't succeed in creating an SOA.

Digital Identity for SOA - Digital identity plays a foundational role in SOA. We will discuss the role of identity systems in your SOA and how such systems can be defined, built, and managed in the enterprise.

Policies - Many people, especially techies are scared or distrustful of policies. We're all familiar with "computer end user policies" that spell out all the things employees can't do--and then are ignored. The fact is that well thought out, carefully planned policies are essential to building loosely coupled systems. We'll cover the types of policies that are needed for loosely coupled SOA and how policies can be effective. Evaluating policies is a key activity in the governance lifecyce and one that's critical to creating policies that work.

Building an Interoperability Framework - If there's one policy that's more important than all the rest, it's the Interoperability Framework (IF). The good news is that an IF is relatively easy to create. An IF is a list of internal and external standards that the organization supports and their current status. It's the most basic part of an SOA policy and critical to achieving interoperability. This is also a good time to talk about what standards exist, what they do, and why you need them.

Tools for Managing Governance Artifacts - Numerous tools exist for managing governance artifacts. Repositories and registries are used to enable service discovery and enforce enterprise policy at design time and deploy time. Web services management systems are used to manage running services and enforce SOA policies at runtime.

Reference Architectures - Reference architectures come in two flavors: "enterprise" and "system-level." An enterprise reference architecture provides the context that system architects need to ensure their designs will fit in with other systems in the enterprise and be able to interoperate. A system-level architecture gives examples and best practices for common enterprise systems that might be deployed in the organization and shows how those systems relate to the enterprise reference architecture.

Tags: soa governance tutorial events infoworld