old-www/HOWTO/Caudium-HOWTO/thepiketag.html

312 lines
5.8 KiB
HTML

<HTML
><HEAD
><TITLE
>The Pike tag</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"><LINK
REL="HOME"
TITLE="Caudium HOWTO"
HREF="index.html"><LINK
REL="UP"
TITLE="Developing with Caudium"
HREF="developing.html"><LINK
REL="PREVIOUS"
TITLE="Your first RXML file"
HREF="firstrxml.html"><LINK
REL="NEXT"
TITLE="Your first Pike script"
HREF="firstpikescript.html"></HEAD
><BODY
CLASS="sect1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Caudium HOWTO</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="firstrxml.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 6. Developing with Caudium</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="firstpikescript.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="thePiketag">6.2. The Pike tag</H1
><P
>&#13; For a complete tutorial and reference manual on Pike, see
<A
HREF="http://pike.oav.net/"
TARGET="_top"
>http://pike.oav.net/</A
>.
</P
><P
>&#13; The Pike tag allows you to easily insert Pike code into your HTML page à la
PHP. This is a good way of learning Pike if you have a PHP background or if
you want to do things very easily and don't worry about perfect results.
</P
><P
>&#13; To do this, you have to load a module in your server. Just select <TT
CLASS="option"
>Load
module</TT
> in the <SPAN
CLASS="abbrev"
>CIF.</SPAN
> and click the <SPAN
CLASS="QUOTE"
>"Pike tag"</SPAN
> image. Then hit save and create
an .html file where your public web files are. Since everybody tells me
that PHP is easy, which is why it's so popular, I took the PHP examples and
converted them to Pike. Here is the result:
</P
><DIV
CLASS="example"
><A
NAME="AEN896"><P
><B
>Example 6-2. The PHP documentation as a Pike tag.</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="programlisting"
>&#13;&#60;html&#62;
&#60;body bgcolor="#FFFFFF"&#62;
&#60;h2&#62;Escaping from HTML&#60;/h2&#62;
&#60;p&#62;
There is one way of escaping from HTML and entering "Pike code mode"
&#60;br /&#62;
&#60;Pike&#62;
output("This is the simplest, and SGML processing instruction");
&#60;/Pike&#62;
&#60;/p&#62;
&#60;h2&#62;Instruction separation&#60;/h2&#62;
&#60;p&#62;
Instructions are separated the same as in C or Perl:
terminate each statement with a semicolon.
The closing tag (container, in fact) also implies the end of the statement,
so the following are equivalent:
&#60;br /&#62;
&#60;Pike&#62;
output ("This is a test");
&#60;/Pike&#62;
&#60;br /&#62;
&#60;Pike&#62; output ("This is a test"); &#60;/Pike&#62;
&#60;/p&#62;
&#60;h2&#62;Comments&#60;/h2&#62;
&#60;p&#62;
Pike supports C, C++ but not Unix shell-style comments. For example:
&#60;Pike&#62;
string tests = "This is a test&#60;br /&#62;"; // this is a one-line C++ style comment
/* This is a multi line comment
yet another line of comment */
tests += "Yet another test";
return tests;
&#60;/Pike&#62;
&#60;/p&#62;
&#60;h2&#62;Melding RXML and Pike&#60;/h2&#62;
You will never see this in PHP.
<A
NAME="AEN899"
HREF="#FTN.AEN899"
>[1]</A
>
This will create a .gif image of 1-2-...-255.
This took 0.4s on my Duron 750 the first time and 0.1s after.
&#60;p&#62;
&#60;gtext scale=0.5&#62;
&#60;Pike&#62;
string output = "";
for(int I = 1; I &#60; 255; I++)
output += I + "-";
return output;
&#60;/Pike&#62;
&#60;/gtext&#62;
&#60;/p&#62;
&#60;/body&#62;
&#60;/html&#62;
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><P
>&#13; The problem with using this is that you will soon see it is not powerful:
</P
><P
></P
><UL
><LI
><P
>&#13; The code will become an ugly mixture of data and code even if you use an object
orientation method. The more your project grows, the less you will be able
to produce something useful.
</P
></LI
><LI
><P
>&#13; The URL will require plenty of those <SPAN
CLASS="QUOTE"
>"&#38;"</SPAN
> symbols and you will have a lot of files
without real organization.
</P
></LI
><LI
><P
>&#13; The performance will not be the best.
</P
></LI
><LI
><P
>&#13; This can be considered as a security risk for servers that are opened
to unknown users (eg. public web servers).
</P
></LI
></UL
><P
>&#13; The next step is to write your first Pike script.
</P
></DIV
><H3
CLASS="FOOTNOTES"
>Notes</H3
><TABLE
BORDER="0"
CLASS="FOOTNOTES"
WIDTH="100%"
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN899"
HREF="thepiketag.html#AEN899"
>[1]</A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>In fact you can... just compile PHP for Caudium :)</P
></TD
></TR
></TABLE
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="firstrxml.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="firstpikescript.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Your first RXML file</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="developing.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Your first Pike script</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>