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