[rt-devel] globals in Mason

Tina Schade Tina.Schade at gmx.de
Wed Mar 24 03:46:28 EST 2004


Hello people,

I work on a connection to a second database. So I wrote following code to 
/opt/rt3/share/html/autohandler:

my $handle = DBIx::SearchBuilder::Handle->new();

$handle->Connect( 'Driver' => 'Pg',
		  'Database' => 'xy',
		  'User' => 'postgres',
		 'Password' => '') or die ("DB Verbindung kann nicht erstellt werden.  $!");
# to try the connection
my $t = new Kunden($handle);
$t->LoadById(326);
print("Kd-Nummer: ", $t->KdNr(), "\n");
------------------------------------------------------------------
Kunden.pm looks like following:

use strict;
package Kunden;
use RT::Record;
use vars qw( @ISA, $handle );
@ISA= qw( RT::Record );

#use DBIx::SearchBuilder::Record;
#@ISA = ('DBIx::SearchBuilder::Record');

sub _Init {
print("in INIT-Methode von kunden.pm.\n");
    my $self = shift;
    $handle = shift;
    $self->_Handle($handle);
    $self->Table("kdb_kunden");
    $self->SUPER::_Init(@_);
    return ($self);
}

sub Create {
    my $self = shift;
    my %args = (
                KdNr => '',
                #etc. other database fields
		  @_);
    $self->SUPER::Create(
                         kdnr => $args{'KdNr'},
                         etc. other database fields
                         );
}

# Tell Record what the primary keys are
sub _PrimaryKeys {
    my $self = shift;
    return['id'];
}

sub _ClassAccessible {
    {KdNr => {read => 1, write => 1, type => 'varchar(12)', default => '0'},
     etc. other database fields
     };
}
1;
-----------------------------------------------------------------------------------------
That works. But I need the $handle in other components and html-files too. 
I added the Line: "PerlSetVar MasonAllowGlobals $handle" to the httpd.conf and 
deleted the my in front of $handle in the autohandler, but no success. Maybe 
I set this line at the wrong place. Where is the right place to set this?
Then I added: 
allow_globals => ['$handle']  in front of 
$handle = DBIx::SearchBuilder::Handle->new();
also no success.

How can I use the $handle in other files?
Does RT have a mechanism which disables globals?? So that I have to change my 
Kunden.pm?

Thanks for help!
Tina




More information about the Rt-devel mailing list