2aac8053b54c76e11be67ac9fe783088f87c942a
[perl/plp/.git] / PLP / FAQ.pod
1 =head1 Frequently Asked Questions about PLP
2
3 =over 10
4
5 =item What does PLP stand for?
6
7 PerlPage. The name used to be HTMPL, but HyperText Markup with Perl Language was too long.
8
9 =item Is PLP hard to install?
10
11 No, it actually is very simple and easy. Quick startup hints are in the PLP main
12 documentation, extensive installation instructions are on the PLP website.
13
14 =item Is Perl code harder than PHP code?
15
16 Yes, it is. But when you get used to Perl, you will probably dislike PHP for
17 the rest of your life. Perl is faster and far more powerful. For both Perl
18 beginners and more advanced Perl coders, PerlMonks is a good Perl forum community.
19 (Please note: PLP is not Perl. Perl is a complete programming language and is
20 not restricted to web based applications. PLP B<uses> Perl, but many people
21 use Perl without PLP.
22
23 =item Can PLP be used with mod_perl?
24
25 Yes. As of 3.00, PLP can be used with mod_perl! And it's very fast!
26
27 =item You seem to promote dirty programming. Can I use strict with PLP?
28
29 PLP can be used for quick-and-dirty hacks in a way similar to PHP. However, it
30 is suitable for larger applications as well. You can use strict if you want.
31 mod_perl Users might like to know that globals are automatically destroyed (as
32 long as you do not switch packages).
33
34 =item How can I make PLP faster?
35
36 With mod_perl, PLP is a lot faster than with CGI. CGI scripts execute an
37 external interpreter, but mod_perl is a Perl interpreter inside Apache.
38
39 =item I already use mod_perl, can I make my scripts even faster?
40
41 Well, you already have scripts that probably are faster than PHP equivalents,
42 but speed maniacs always want more. Modules are cached, so with a proper module
43 design, you can add a little more speed.
44
45 =item Can I use Perl's CGI module with PLP?
46
47 You certainly can! If you do not want %get and %post and the like, just not use
48 them. They will be generated on first access, so if you never access them, the
49 hashes are never filled.
50
51 If you want to use CGI.pm's header functions, C<select STDOUT;> first, to break
52 out of PLP's tied C<PLPOUT> filehandle.
53
54 =item Why does C<< <($filename)> >> not work?
55
56 C<< <(...)> >> is a compile-time tag, opposed to C<include()>, which is evaluated at
57 run-time. At compile time, variables are not yet known, and PLP will try to
58 include a file literally called C<$filename>.
59
60     <: $filename = 'foo.inc.plp'; include($filename); :>
61
62 =item Why do my variables not work in my C<include()>d file?
63
64 That is because your variable is lexical (declared with C<my>), and the file is
65 evaluated in its own scope, just as with Perl's built-in C<do> and C<require>.
66 You can pass variables through subroutine parameters or by using globals
67 variables. Another solution is using PLP's C<< <(...)> >> tag.
68
69 =item But why do they work with C<< <()> >> then?
70
71 Because it places the external file is placed inside of the other,
72 B<before> the code is executed (at compile-time).
73
74 =item Why do my C<END> blocks never get executed?
75
76 If they are not, you are probably running under mod_perl. The blocks are
77 executed when the interpreter stops, but the mod_perl interpreter is not exited
78 after the PLP script has ended. Use C<PLP_END> blocks instead. Please note that
79 C<PLP_END> is a normal statement, so you may need a semicolon.
80
81     <html><body>
82     <: PLP_END { :>
83         </body></html>
84     <: } :>
85
86 =item Can I disable the error messages?
87
88 You can not disable compile-time errors (syntax errors), but you can disable
89 run-time errors. To do so, set the 0-bit (1) of C<$PLP::DEBUG> off. If you only
90 want error reporting disabled for a single command, use Perl's C<eval BLOCK>
91 function (not C<eval "">, but C<eval {}>, which is not slow or insecure.).
92
93     <: $PLP::DEBUG ^= 1 if $PLP::DEBUG & 1; :>
94
95 =item Can I have my own error messages?
96
97 Yes, you can! Of course, you can not override compile-time errors like syntax
98 errors, but run-time error messages use C<$PLP::ERROR>, which is a reference to a
99 sub that gets two arguments: the error message itself, and an html-encoded
100 version.
101
102     <:
103         $PLP::ERROR = sub {
104             my ($plain, $html) = @_;
105             print '<font color="red">', $html, '</font>';
106         };
107     :>
108
109 =item Is there a way to see the headers that PLP sends?
110
111 There is. Set C<$PLP::DEBUG>'s 1-bit (2), and it will output a plain text header
112 before outputting the other one.
113
114     <: $PLP::DEBUG ^= 2 unless $PLP::DEBUG & 2 :>
115
116 =back
117
118 =cut
119