If you wrap some Perl code in <% ... %> tags, the result of the Perl expression is inserted into the resulting HTML.
That's all very well for simple expressions, but what about actual Perl logic? For this, Mason has an ugly hack: a single % at the beginning of a line is interpreted as Perl code. This lets you do things like Example 3-4, to dump out the contents of a hash.
There's a few things to notice in this example. First, see how we intersperse ordinary HTML with logic, using % ... , and evaluated Perl expressions, using <% ... %>. The only places % is special are at the start of a line and as part of the <% ... %> tag; the % of %hash is plain Perl.
The second thing to notice in the example is how we get the hash into the component in the first place. That's the purpose of the <%ARGS> section--it declares arguments to pass to the component. And how do we pass in those arguments? Here's something that might call Hashdump:
% my %foo = ( one => 1, two => 2 );
<& /Hashdump, hash => %foo &>
So altogether, we have an example of declaring my variables inside a component, passing a named parameter to another component, and having that component receive the parameter and make use of it. Mason will try to do something sensible if you pass parameters of different types than the types you've declared in the <%ARGS> section of the receiving component (here we passed a hash to fill in the %hash parameter, for instance), but life is easier if you stick to the same types.
Please check back next week for the continuation of this series.