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