Gantry::Utils::DBConnHelper::MP13 - connection info and dbh cache manager for mod_perl 1


Gantry documentation Contained in the Gantry distribution.

Index


Code Index:

NAME

Top

Gantry::Utils::DBConnHelper::MP13 - connection info and dbh cache manager for mod_perl 1

SYNOPSIS

Top

    use Gantry::Utils::DBConnHelper::MP13;

    # put these PerlSetVars in your conf (as needed):
    #   dbconn
    #   dbuser
    #   dbpass
    #   auth_dbconn
    #   auth_dbuser
    #   auth_dbpass

DESCRIPTION

Top

When you use a model which inherits from Gantry::Utils::CDBI or Gantry::Utils::Model, using this module can help with database connection management. Feel free to implement your own subclass of Gantry::Utils::DBConnHelper if you need more control.

This module is designed to work with mod_perl 1.3. There is another module for mod_perl 2 candidates: Gantry::Utils::DBConnHelper::MP20.

METHODS

Top

See Gantry::Utils::DBConnHelper for a description of the methods available here. But note that there are no set_conn_info or set_auth_conn_info methods. All values are taken from PerlSetVars.

If you do not define an auth_dbconn PerlSetVar, this module will return the regular connection information, if it is ever asked for auth connection information.

Here is a list of the methods documented in Gantry::Utils::DBConnHelper.

get_auth_conn_info
get_auth_dbh
get_conn_info
get_dbh
set_auth_dbh
set_dbh

AUTHOR

Top

Phil Crow <philcrow2000@yahoo.com>

COPYRIGHT and LICENSE

Top


Gantry documentation Contained in the Gantry distribution.

package Gantry::Utils::DBConnHelper::MP13;
use strict; use warnings;

use Gantry::Conf;

use base 'Gantry::Utils::DBConnHelper';

Gantry::Utils::DBConnHelper->set_subclass(
    'Gantry::Utils::DBConnHelper::MP13'
);

#----------------------------------------------------------------
# Methods for regular connections
#----------------------------------------------------------------

sub get_dbh {
    my $dbh;
    my $r = Apache->request();
    
    if ( not $Apache::ServerStarting ) {
        $dbh = $r->pnotes( 'dbh' );
    }

    return $dbh;
}

sub set_dbh {
    my $class = shift;
    my $dbh   = shift;
    my $r     = Apache->request();

    if ( not $Apache::ServerStarting ) {
        $r->pnotes( 'dbh', $dbh );
    }
}

sub _get_gantry_conf {
    my $r = shift;
    my $location = $r->location;
    my $instance   = $r->dir_config( 'GantryConfInstance' );
    my $conf;

    return unless defined $instance;

    my $gconf_file = $r->dir_config( 'GantryConfFile' );

    # Check for a cached version first.
    $conf = $r->pnotes( "conf_${instance}_${location}" );
    
    unless ($conf) {
        $conf = Gantry::Conf->retrieve(
            {
                instance    => $instance,
                config_file => $gconf_file,
            }
        );
        
        $r->pnotes( "conf_${instance}_${location}", $conf );
    }
    
    return $conf;
}

sub get_conn_info {
    my $r           = Apache->request();
    my $gantry_conf = _get_gantry_conf( $r );

    if ( $gantry_conf ) {
        return {
            dbconn => $gantry_conf->{ 'dbconn' },
            dbuser => $gantry_conf->{ 'dbuser' },
            dbpass => $gantry_conf->{ 'dbpass' },
        }
    }
    else  {
        return {
            dbconn => $r->dir_config( 'dbconn' ),
            dbuser => $r->dir_config( 'dbuser' ),
            dbpass => $r->dir_config( 'dbpass' ),
        };
    }
}

#----------------------------------------------------------------
# Methods for auth connections
#----------------------------------------------------------------

sub get_auth_dbh {
    my $auth_dbh;
    my $r = Apache->request();

    if ( not $Apache::ServerStarting ) {
        $auth_dbh = $r->pnotes( 'auth_dbh' );
    }

    return $auth_dbh;
}

sub set_auth_dbh {
    my $class    = shift;
    my $auth_dbh = shift;
    my $r        = Apache->request();

    if ( not $Apache::ServerStarting ) {
        $r->pnotes( 'auth_dbh', $auth_dbh );
    }
}

sub get_auth_conn_info {
    my $r           = Apache->request();
    my $gantry_conf = _get_gantry_conf( $r );
    my $auth_conn;
    
    $auth_conn->{ auth_dbconn } =   $gantry_conf->{ 'auth_dbconn' } ||
                                    $r->dir_config( 'auth_dbconn' ) ||
                                    $gantry_conf->{ 'dbconn' } ||
                                    $r->dir_config( 'dbconn' );
    
    $auth_conn->{ auth_dbuser } =   $gantry_conf->{ 'auth_dbuser' } ||
                                    $r->dir_config( 'auth_dbuser' ) ||
                                    $gantry_conf->{ 'dbuser' } ||
                                    $r->dir_config( 'dbuser' );
    
    $auth_conn->{ auth_dbpass } =   $gantry_conf->{ 'auth_dbpass' } ||
                                    $r->dir_config( 'auth_dbpass' ) ||
                                    $gantry_conf->{ 'dbpass' } ||
                                    $r->dir_config( 'dbpass' );
    
    return $auth_conn;
}

1;