File: cooking.pod

package info (click to toggle)
libapache2-mod-perl2 2.0.9~1624218-2%2Bdeb8u2
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 11,912 kB
  • ctags: 4,588
  • sloc: perl: 95,064; ansic: 14,527; makefile: 49; sh: 18
file content (121 lines) | stat: -rw-r--r-- 2,613 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
=head1 NAME

Cooking Recipes

=head1 Description

As the chapter's title implies, here you will find ready-to-go
mod_perl 2.0 recipes.

If you know a useful recipe, not yet listed here, please post it to
L<the mod_perl mailing list|maillist::modperl> and we will add it
here.

=head1 Sending Cookies in REDIRECT Response (ModPerl::Registry)

  use CGI::Cookie ();
  use Apache2::RequestRec ();
  use APR::Table ();
  
  use Apache2::Const -compile => qw(REDIRECT);
  
  my $location = "http://example.com/final_destination/";
  
  sub handler {
      my $r = shift;
  
      my $cookie = CGI::Cookie->new(-name  => 'mod_perl',
                                    -value => 'awesome');
  
      $r->err_headers_out->add('Set-Cookie' => $cookie);
      $r->headers_out->set(Location => $location);
      $r->status(Apache2::Const::REDIRECT);
  
      return Apache2::Const::REDIRECT;
  }
  1;


=head1 Sending Cookies in REDIRECT Response (handlers)

  use CGI::Cookie ();
  use Apache2::RequestRec ();
  use APR::Table ();
  
  use Apache2::Const -compile => qw(REDIRECT);
  
  my $location = "http://example.com/final_destination/";
  
  sub handler {
      my $r = shift;
  
      my $cookie = CGI::Cookie->new(-name  => 'mod_perl',
                                    -value => 'awesome');
  
      $r->err_headers_out->add('Set-Cookie' => $cookie);
      $r->headers_out->set(Location => $location);
  
      return Apache2::Const::REDIRECT;
  }
  1;

note that this example differs from the Registry example
only in that it does not attempt to fiddle with 
C<$r-E<gt>status()> - C<ModPerl::Registry> uses C<$r-E<gt>status()>
as a hack, but handlers should never manipulate the
status field in the request record.

=head1 Sending Cookies Using libapreq2

  use Apache2::Request ();
  use Apache2::RequestRec ();
  use Apache2::Const -compile => qw(OK);
  
  use APR::Table ();
  use APR::Request::Cookie ();
  
  sub handler {
      my $r = shift;
      my $req = $r->pool();
      
      my $cookie = APR::Request::Cookie->new($req, name => "foo", value => time(), path => '/cookie');
      
      $r->err_headers_out->add('Set-Cookie' => $cookie->as_string);
      
      $r->content_type("text/plain");
      $r->print("Testing....");
      
      return Apache2::Const::OK;
  }

=head1 Maintainers

Maintainer is the person(s) you should contact with updates,
corrections and patches.

=over

=item *

Stas Bekman [http://stason.org/]

=back

=head1 Authors

=over

=item *

Stas Bekman [http://stason.org/]

=back

Only the major authors are listed above. For contributors see the
Changes file.


=cut