]> git.decadent.org.uk Git - maypole.git/blob - lib/CGI/Maypole.pm
2.04 release stuff
[maypole.git] / lib / CGI / Maypole.pm
1 package CGI::Maypole;
2 use base 'Maypole';
3
4 use strict;
5 use warnings;
6
7 our $VERSION = '2.04';
8
9 sub run {
10     my $self = shift;
11     return $self->handler();
12 }
13
14 sub get_request {
15     require CGI::Simple;
16     shift->{cgi} = CGI::Simple->new();
17 }
18
19 sub parse_location {
20     my $self = shift;
21     $self->{path} = $self->{cgi}->url( -absolute => 1, -path_info => 1 );
22     my $loc = $self->{cgi}->url( -absolute => 1 );
23     no warnings 'uninitialized';
24     $self->{path} =~ s/^($loc)?\///;
25     $self->parse_path;
26     $self->parse_args;
27 }
28
29 sub parse_args {
30     my $self = shift;
31     my (%vars) = $self->{cgi}->Vars;
32     while ( my ( $key, $value ) = each %vars ) {
33         my @values = split "\0", $value;
34         $vars{$key} = @values <= 1 ? $values[0] : \@values;
35     }
36     $self->{params} = {%vars};
37     $self->{query}  = {%vars};
38 }
39
40 sub send_output {
41     my $r = shift;
42     print $r->{cgi}->header(
43         -type           => $r->{content_type},
44         -charset        => $r->{document_encoding},
45         -content_length => length $r->{output},
46     );
47     print $r->{output};
48 }
49
50 sub get_template_root {
51     my $r = shift;
52     $r->{cgi}->document_root . "/" . $r->{cgi}->url( -relative => 1 );
53 }
54
55 1;
56
57 =head1 NAME
58
59 CGI::Maypole - CGI-based front-end to Maypole
60
61 =head1 SYNOPSIS
62
63      package BeerDB;
64      use base 'CGI::Maypole;
65      BeerDB->setup("dbi:mysql:beerdb");
66      BeerDB->config->uri_base("http://your.site/cgi-bin/beer.cgi/");
67      BeerDB->config->display_tables([qw[beer brewery pub style]]);
68      # Now set up your database:
69      # has-a relationships
70      # untaint columns
71
72      1;
73
74      ## example beer.cgi:
75         
76      #!/usr/bin/perl -w
77      use strict;
78      use BeerDB;
79      BeerDB->run();
80
81 =head1 DESCRIPTION
82
83 This is a handler for Maypole which will use the CGI instead of Apache's
84 C<mod_perl> 1.x. This handler can also be used for Apache 2.0.
85
86 =head1 METHODS
87
88 =over
89
90 =item run
91
92 Call this from your CGI script to start the Maypole application.
93
94 =back
95
96 =head1 Implementation
97
98 This class overrides a set of methods in the base Maypole class to provide it's 
99 functionality. See L<Maypole> for these:
100
101 =over
102
103 =item get_request
104
105 =item get_template_root
106
107 =item parse_args
108
109 =item parse_location
110
111 =item send_output
112
113 =back
114
115 =head1 AUTHORS
116
117 Dave Ranney C<dave@sialia.com>
118
119 Simon Cozens C<simon@cpan.org>