Home Page
make a choice: Photoshop 7 or Photoshop CS/CS 2
Uncle Gugl - a giant
How to name a Web-site?
Spam - a problem of a century
register_globals=oN? You in danger!
Gathering of statistics on PHP
Transformation XML + XSLT with help Sablotron
Patterns of documents and Perl
The signature or avatars on pkhp
Privatnost` in the Internet
Use of the module for job with patterns
Alternative MIME:: Parser and Email:: Simple
Job with sessions in perl
Creation of dynamic forms with help JavaScript
*.JS when to be loaded you think?
Module CGI.pm
XML in 10 theses
Platformo-independent dynamic site - a myth or a reality?
Something about WAP
 


Use of the module for job with patterns

There is enough of modules for job with patterns HTML.


All of them have the advantages and lacks. The module described in the given clause{article} is not capable to become leading, and such purpose at his  creation was not put. This library raschitana on the certain circle of problems{tasks}, and probably for large Web-projects she will not approach. Though there are serious enough commercial jobs using the given module.


The module is development of the author and does not apply for accommodation on CPAN.


I shall not stop on as far as use of patterns is convenient. I shall stop only on offered{suggested} variants of realization (and the resulted ways are not exhaustive). And then I shall result the brief description of the offered{suggested} module.



Module Text:: Template


Here the code perl is inserted into a pattern, using braces. The mechanism of a spelling of a pattern has seemed unnatural and confusing. As if your patterns will be edited by the designer, it will be rather difficult for him to distinguish promezhetochnye variables, from that that it is necessary to deduce{remove} on page. (the complex  organization of patterns - with use of cycles, etc.) Here is meant



Module Template


Rather taki gromozkij the module. Approaches for all stuacij. But patterns are created with the help of own logic reminding the own programming language. Therefore to work with this module it is necessary to lead{carry out} enough time behind reading of the documentation. I.e. it is necessary to study this language in addition still.


As interpretation (analysis) of such patterns will borrow{occupy} much more time, than we shall say realization danoj logic on perl. In addition given module does not enter into delivery perl and is established far from being on all hostings. And about free-of-charge and to speak it is not necessary (www.f2s.com, webservis.ru, wallst.ru, holm.ru, hut.ru). The way of simple copying of the module works only in 50 %. If you write kommerchesij a product the given circumstance can reduce a circle of potential buyers.



Module CGI:: FastTemplate


All is good. And probably on this module it was possible to stop search.


But also here not all how is to be seen. At job with tables (where the quantity{amount} of lines is defined{determined} during job and as and) should be stored{kept} in some other cases different elements in different files. It in my opinion is terribly inconvenient both for the designer, and for the programmer. At a spelling of the average program (suzhu by the experience) the quantity{amount} of such files can reach{achieve} about 20-25 sht (at use of this module). And as usually all patterns are stored{kept} in one directory it is possible to get confused simply in them.



Module HTML:: EmbPerl


The most suitable variant. But as well as vsluchae with Template it is established not everywhere. And I had to refuse his  use. As has the impressive size. The mechanism of embedding of a code perl in page has seemed not so convenient, though it on the fan{amateur}.



And now about the main thing


At me for a long time was zadumka - to build a code perl in pages (like PHP), even before acquaintance to the set forth above modules. And this zadumka has been realized in the described module. The module borrows{occupies} all a little bit{some} kilobyte and does not depend on operational system.


The idea is simple. The code perl consists in tegi <% of %>. That would be more understandable, I shall result an example of a pattern.



<body>


<center> <h3> Test Page </h3> </center> <br> <br>


<%


print " <font color=red> <h3> $MESG </h3> </font> " if $MESG;


%>


<table cellpaddind=1 cellspasing=1>


<tr bgcolor = * 91af6d>


<td> N </td>


<td> 1 </td>


<td> 2 </td>


<td> 3 </td>


<td> 4 </td>


<td> 5 </td>


<td> 6 </td>


<td> 7 </td>


<td> 8 </td>


<td> 9 </td>


<td> 10 </td>


</tr>


<%


* = == Perl Code


for ($x = 0; $x <scalar ($STAT); $x ++) {


if (int ($x/2) == ($x/2)) {$bgcolor = "*ffffff"}


else {$bgcolor = "*c0d8bc"}


print qq {<tr bgcolor = $ bgcolor>};


print qq {<td> $ {\ ($x+1 + $ INDEX)} </td>};


print qq {<td> $STAT-> [$ x] [1] </td>


<td> $STAT-> [$ x] [2] </td>


<td> $STAT-> [$ x] [3] </td>


<td> $ {\ ($STAT-> [$ x] [4] == 0? $STAT-> [$ x] [4]: "YES")} </td>


<td> $STAT-> [$ x] [5] </td>


<td> $STAT-> [$ x] [9] </td>


<td> $STAT-> [$ x] [10] </td>


<td> $STAT-> [$ x] [6] </td>


<td> $STAT-> [$ x] [7] </td>


<td> $STAT-> [$ x] [8] </td>};


print qq {</tr> \n};


last if $x == ($STOP-1);


}


* = ==


%>


If on page it is necessary to deduce{remove} simply value of a variable it is done{made} so <% print $VAR %>. Pay attention on ' print '. He is obligatory.

Transfer of parameters to a pattern is carried out so:



use STemplate;


my $temp = STemplate-> new ();


my %data = (


$MESG => ' Y ',


$SSS => ($ee == 1? ' Y ':' N '),


$STAT => [$array_ref1, $array_ref2...],


$STOP => getstop () * procedure


* Returning


* A scalar


);


print " Content-type: text/html\n\n ";


$temp-> template ($TEMP_DIR, $TEMP_FILE, \ %data) || die;


Thus all keys khesha %data become variables in a pattern.


As values %data it is possible to pass only scalars (it is meant that links as are scalars).


If filling (content) of page undertakes from the Database as a key %data it is possible to set object of a database. And in the pattern to cause through him  necessary methods.



$dbh = DBI-> connect (....);


...


$data {' DBH '} = $dbh;


...


Pattern


...


$sel = $DBH-> prepare (' SELECT * FROM TABLE ');


$sel-> execute () || die;


$table = $sel-> fetchall_arrayref ();


$sel-> finish ();


...


In $table there is the file of files containing all the line long from the table.


Access to the certain attribute is carried out-



$table-> [NOMER_STROKI-1] [NOMER_ATRIBUTA-1].


If you do not want to deduce{remove} result of processing nablona on the screen, and we shall say, it is necessary to save all in a file. Then before a call of a method ' template ' open a file (open (FILE....)), and then establish a stream of a conclusion by default - select (FILE).


If there is an access to adjustments Apache it is possible to set obrabotchik for all pages with the certain expansion. We shall say .plhtm.


I hope as you will find, something useful to yourself in this module and probably switch on it  in some development.



© Web Development Company Conkurent, LLC 2007-2009. All rights reserved.