]> git.decadent.org.uk Git - maypole.git/blob - lib/CGI/Maypole.pm
added rewrite_path()
[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->rewrite_path;
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 AUTHORS
87
88 Dave Ranney C<dave@sialia.com>
89
90 Simon Cozens C<simon@cpan.org>