added howto documentation
[perl/plp/.git] / PLP / HowTo.pod
1 =head1 Name
2
3 PLP::HowTo - Some examples of commong web things in PLP.
4
5 =head1 How to...
6
7 Additional Perl functionality is often available in modules. All of the modules
8 used in this document are available (for free) at CPAN: http://search.cpan.org/
9
10 =over 10
11
12 =item send a cookie
13
14     <: 
15         BEGIN {
16             use CGI::Cookie;
17             AddCookie( CGI::Cookie->new(
18                 -name => 'ID',
19                 -value => 123456,
20                 -domain => 'foo.com',
21                 -path => '/'
22             )->as_string );
23         }
24     :>
25
26 =item get a cookie
27
28     Your user ID is <:= $cookie{ID} :>
29
30 =item set a header
31
32     <:
33         BEGIN {
34             $header{Content_Type} = 'text/plain';
35         }
36     :>
37
38 =item use a database
39
40 Use DBI, and alternatively, one of the many simplifying modules. Drivers for
41 DBI are in the DBD:: namespace. DBI loads the driver automatically, but it has
42 to be available.
43
44     <:
45         use DBIx::Simple; # and read its documentation for examples.
46     :>
47
48 =item allow a user to upload a file
49
50 Use CGI.pm, which can be used with CGI::Upload to make things easier
51
52     <:
53         use CGI;         # and don't use %post in your PLP document.
54         use CGI::Upload; # and read its documentation for examples.
55         my $cgi = CGI->new;
56         my $upload = CGI::Upload->new($cgi);
57         ...
58     :>
59 =item download a file into a variable
60
61     <:
62         use LWP::Simple;
63         my $page = get("http://foo.com/bar.html");
64     :>
65
66 =back
67
68 If you have good, simple examples of how to do common things with PLP, please
69 send them! (juerd@cpan.org)
70
71 =cut
72