Home Links
Home Page
How to us to correct the person who has entered
Yandex - like search by the hands
Stemmer.
Creation of sites - model of qualitative imposition
Entrance parameter of function is the file from six elements
Promotion of a site in Rambler
The good design should make a profit
Validnost` HTML
Perenapravlenie mistakes in a browser - 100 % as in PHP
Terrible animal the traffic
Cajt with help HTML:: Mason
Choice of the module
Bases of
Creation of a site
Adjustment of a site
TT - the counter of the traffic
GetCurrBytes
OnOverflow
Small improvements of our counter
 

Bases of "cursor" Mason


As it has already been said, Mason allows to build a Perl-code in the document. It can be made in several ways, each of which is convenient in different situations.

As values of global variables are not destroyed after end of the program (feature mod_perl) all used variables are necessary for declaring as lexical, except for the certain cases about which it will be told later. Otherwise component Mason will not pass compilation as all code is checked pragmoj strict.

Now about bases of syntax Mason.

1. The line beginning with a symbol of %, is perceived, as a Perl-code. This design is very convenient in managing operators. An example:



% if ($browser = ~/msie/i) {

<h3> you use Internet Explorer </h3>

%} else {

<h3> At you, most likely, Netscape </h3>

%}


Minimum of syntax, maximum of convenience.

2. The block <% EXPR of %> is replaced with result of calculation of expression EXPR. usually applied to a conclusion of variables. An example:



Hello, <% $name %>

<% ($name? " Hello, $name ": " ") %>


In the block the opportunity of formatting of result is stipulated:



<% $html_tags |h %> - replaces all '<' on ' *lt; ', etc.

<% $string |u %> - transforms a line in urlencoded (an example: ':' it is replaced on '%3A')


3. The big Perl-blocks can be inserted between tegami <%perl...> </%perl>

4. In components two global objects are accessible. The first - $r, object of module Apache, from him{it} it is possible to cause all methods of this module, the second - $m, object Mason. The object $m, provides access to very useful methods which full description can be found in the documentation to Mason (perldoc HTML:: Mason:: Request). An example of use of object $r:



% my $ua = $r-> header_in ('User-Agent');

% my $host = $r-> get_remote_host;


5. Mason would not be so it is popular, if in him it was impossible to connect other components. The complex{difficult} document happens to be broken into some files conveniently. Identical components can be used in different pages, passing them corresponding parameters. There are two ways of a call of components. The first is intended for an insert in HTML, the second represents a method of object $m. An example:



1) <and/path/comp_name, par1 => $value1, par2 => $value2 ?>

2) $m-> comp ('/path/comp_name ', par1 => $value1, par2 => $value2);


The way is calculated be relative MasonCompRoot. As parameters it is possible to pass links to files and khehshi. Other variables in the called component are inaccessible.

6. If there is an opportunity to pass the data, there should be a way of them take. Here Mason again offers some ways. And is unimportant, whether these parameters through search GET (POST) are passed or by a call of a component.


The first way


KHehsh %ARGS contains all transferred{handed} parameters. If names of parameters repeat (for example, at use checkbox) the corresponding key khehsha contains the link to a file. On the one hand, khehsh it is convenient for the developer, he allocates variables to which it is necessary concerns with the big care as they are passed from the user. With another, recordings look is very bulky. Mason offers an alternative variant of reception of parameters.


The second way



<%args>

$par1 => undef

@par2 => undef

</%args>


Here all is understandable, undef the ambassador => sets a default value if in the entrance data the parameter will be absent. Repeating parameters get in a file.

7. Section <%init...> </%init> and <%cleanup...> </%cleanup> define{determine} a code of initialization and end accordingly.