The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Maypole::Virtual::Application - create multiple Maypole apps on the fly

SYNOPSIS

    package BeerDB;
    use strict;
    use warnings;
    
    use Class::DBI::Loader::Relationship;
    
    use Maypole::Virtual::Application; 
    
    Maypole::Virtual::Application->install_packages( qw( -Debug AutoUntaint ) );
    
    # beer for everyone!
    sub virtual_packages { map { __PACKAGE__ . "::Site$_" } 1 .. 100 }
    
    sub initialize_package
    {
        my ( $self, $package ) = @_;
        
        $package =~ /(Site\d+)$/;
        
        my $site = $1;
        
        my $username = My::Config::System->get_beerdb_username_for( $site );
        my $password = My::Config::System->get_beerdb_password_for( $site );
        
        $package->setup( "dbi:mysql:BeerDB$site", 
                         $username,
                         $password,
                         );
        
        $package->config->{template_root}  = '/home/beerdb/www/www/htdocs';
        $package->config->{uri_base}       = '/';
        $package->config->{rows_per_page}  = 10;
        $package->config->{display_tables}   = [ $package->config->loader->tables ]; 
        $package->config->{application_name} = 'The Beer Database';
        
        $package->auto_untaint;
        
        $package->config->loader->relationship( $_ ) for (
            'a brewery produces beers',
            'a style defines beers',
            'a pub has beers on handpumps',
            );
                
        # this would get called anyway during the first request, but 
        # putting it here is useful under mod_perl to get all initialisation 
        # done before forking off child servers
        $package->init;
    }
    
    sub my_custom_request_method
    {
        # all virtual apps inherit from this package (BeerDB in this case), 
        # so methods defined here are inherited by all Maypole request objects 
        # in the virtual apps.
    }
    
    1;
    

DESCRIPTION

Use this class to setup multiple applications 'on the fly'. This might be useful in a mod_perl virtual hosting environment, where you want to give each site its own version of a Maypole application.

METHODS

install_packages( @plugins )

Pass the list of plugins and flags to be installed in each application, just as with Maypole::Application. This method then uses the virtual_packages callback to get a list of package names to install, installs each package using Maypole::Application, and runs the initialize_package callback to configure each package.

Maypole::Application

There's a bug in Maypole::Application that needs to be fixed before using this module. You can download a fixed version of Maypole::Application from beerdb.riverside-cms.co.uk, until the patch is incorporated in Maypole::Application proper. That version of Maypole::Application also works with MasonX::Maypole (as well as the other Maypole frontends). The build script should check for version 2.10, as does the main package, so you should install the patched Maypole::Application before attempting to install this.

AUTHOR

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

BUGS

Please report any bugs or feature requests to bug-maypole-virtual-application@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Maypole-Virtual-Application. 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.