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