NAME

Maypole::Plugin::Config::Apache - read config settings from httpd.conf

SYNOPSIS

use Maypole::Application qw( Config::Apache -Setup );


# in httpd.conf

PerlSetVar MaypoleApplicationName "The Beer Database"
PerlSetVar MaypoleUriBase         /beerdb
PerlSetVar MaypoleTemplateRoot    /home/beerdb/www/beerdb/htdocs
PerlSetVar MaypoleRowsPerPage     10

PerlSetVar MaypoleDsn             "dbi:mysql:BeerDB"
PerlSetVar MaypoleUser            username
PerlSetVar MaypolePass            password

# set a listref
PerlAddVar MaypoleDisplayTables  beer 
PerlAddVar MaypoleDisplayTables  brewery 
PerlAddVar MaypoleDisplayTables  pub 
PerlAddVar MaypoleDisplayTables  style

# set a hashref
PerlAddVar MaypoleMasonx "data_dir   => '/home/beerdb/www/beerdb/mdata'"
PerlAddVar MaypoleMasonx "in_package => 'BeerDB::TestApp'"
PerlAddVar MaypoleMasonx "comp_root => [ [ factory => '/usr/local/www/maypole/factory' ] ]"

# set something from Perl code
PerlSetVar MaypoleEvalFlooberiser "[ [ foo => 'bar', baz => { bee => 'boo } ] ]"

# get lazy with lists
PerlSetVar MaypoleEvalDisplayTables "[ qw( beer brewery pub style ) ]"

DESCRIPTION

Anything starting with Maypole or MaypoleEval is taken to be a config setting for Maypole. Everything after the Maypole or MaypoleEval is the variable name, in StudlyCaps form.

Values from MaypoleEval variables are run through an eval, allowing arbitrarily complex data structures to be set, including coderefs, if anything needed that.

Any value from a PerlAddVar that contains a => symbol is also run through an eval, so any valid perl expression for a hash value can be used.

Put Config::Apache at the front of the Maypole::Application call, so that later plugins have access to the configuration settings. If your httpd.conf contains all of your Maypole settings, you can add the -Setup flag, which calls __PACKAGE__->setup for you.

METHODS

setup

EXAMPLE

With all the config moved to httpd.conf, the actual driver is reduced to a few lines of code. Why not inline that in httpd.conf too?

<VirtualHost xxx.xxx.xx.xx>
    
    ServerName beerdb.riverside-cms.co.uk
    ServerAdmin cpan@riverside-cms.co.uk

    DocumentRoot /home/beerdb/www/beerdb/htdocs
    
    #
    # Set up Maypole via Maypole::Plugin::Config::Apache
    #
    PerlSetVar MaypoleApplicationName "The Beer Database"
    PerlSetVar MaypoleUriBase         /beerdb
    PerlSetVar MaypoleTemplateRoot    /home/beerdb/www/beerdb/htdocs
    PerlSetVar MaypoleRowsPerPage     10
    
    PerlSetVar MaypoleDsn             "dbi:mysql:BeerDB"
    PerlSetVar MaypoleUser            username
    PerlSetVar MaypolePass            password
    
    PerlAddVar MaypoleDisplayTables  beer 
    PerlAddVar MaypoleDisplayTables  brewery 
    PerlAddVar MaypoleDisplayTables  pub 
    PerlAddVar MaypoleDisplayTables  style
    
    PerlAddVar MaypoleMasonx "comp_root  => [ [ factory => '/usr/local/www/maypole/factory' ] ]"
    PerlAddVar MaypoleMasonx "data_dir   => '/home/beerdb/www/beerdb/mdata'"
    PerlAddVar MaypoleMasonx "in_package => 'BeerDB::TestApp'"
    
    PerlAddVar MaypoleRelationships     "a brewery produces beers"
    PerlAddVar MaypoleRelationships     "a style defines beers"
    PerlAddVar MaypoleRelationships     "a pub has beers on handpumps"
    
    <Directory /home/beerdb/www/beerdb/htdocs/>
        Allow from all
        AllowOverride none
        Order allow,deny

        <Perl>
        {
            package BeerDB;
            use Maypole::Application qw( Config::Apache MasonX AutoUntaint Relationship -Setup -Debug2 );
            BeerDB->auto_untaint;
            BeerDB->init;
        }
        </Perl>
        
        SetHandler perl-script
        PerlHandler BeerDB
    </Directory>
    
    CustomLog /home/beerdb/www/beerdb/logs/access.log combined env=log
    ErrorLog  /home/beerdb/www/beerdb/logs/error.log    
    
</VirtualHost>

Watch out for the chicken and the egg. The Perl section defining the BeerDB package must come after all the Maypole config settings (or else the settings won't yet exist when BeerDB tries to read them), but before the PerlHandler BeerDB directive (because the package needs to exist by then).

AUTHOR

David Baird, <cpan@riverside-cms.co.uk>

BUGS

I think a hash with a single entry might not work, prod me if you need this.

Please report any bugs or feature requests to bug-maypole-plugin-config-apache@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Maypole-Plugin-Config-Apache. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2005 David Baird, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.