Changeset 10575 for trunk/Nebulous-Server
- Timestamp:
- Dec 8, 2006, 10:57:51 AM (20 years ago)
- Location:
- trunk/Nebulous-Server
- Files:
-
- 2 edited
-
Changes (modified) (1 diff)
-
lib/Nebulous/Server.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/Changes
r10546 r10575 6 6 - add a DESTROY method to Nebulous::Server to tear down the database 7 7 connection 8 - add a Nebulous::Server->config() accessor 9 - make Nebulous::Server->db() Apache::DBI aware 8 10 9 11 0.02 Fri Dec 2 17:36:59 HST 2005 -
trunk/Nebulous-Server/lib/Nebulous/Server.pm
r10546 r10575 1 1 # Copyright (c) 2004 Joshua Hoblitt 2 2 # 3 # $Id: Server.pm,v 1.2 0 2006-12-08 03:29:19jhoblitt Exp $3 # $Id: Server.pm,v 1.21 2006-12-08 20:57:36 jhoblitt Exp $ 4 4 5 5 package Nebulous::Server; … … 20 20 use Params::Validate qw( validate_pos SCALAR ); 21 21 22 __PACKAGE__->mk_accessors(qw( log sql db));22 __PACKAGE__->mk_accessors(qw( log sql config )); 23 23 24 24 sub new { … … 66 66 $self->sql($sql); 67 67 $self->db($db); 68 $self->config($config); 68 69 69 70 return $self; 71 } 72 73 sub db { 74 my $self = shift; 75 76 if (@_) { 77 $self->{db} = $_[0]; 78 return $self; 79 } 80 81 my $log = $self->log; 82 my $sql = $self->sql; 83 my $config = $self->config; 84 85 # if we're running under mod_perl & Apache::DBI is loaded we want to 86 # reconnect to the database everytime the dbh is request. The rational is 87 # that if we're running under mod_perl this is probably a log running 88 # processes and the database might have gone away on us. Apache::DBI will 89 # take care of getting a valid dbh back. 90 if ($INC{'Apache/DBI.pm'} && $ENV{MOD_PERL}) { 91 my $db; 92 eval { 93 $db = DBI->connect( 94 $config->dsn, 95 $config->dbuser, 96 $config->dbpasswd, 97 { 98 RaiseError => 1, 99 PrintError => 0, 100 AutoCommit => 0, 101 }, 102 ); 103 104 $db->do( $sql->set_transaction_model ); 105 106 $db->commit; 107 }; 108 if ( $@ ) { 109 $db->rollback if $db; 110 $log->logdie( "database error: $@" ); 111 } 112 113 $self->{db} = $db; 114 115 return $db; 116 } 117 118 return $self->{db}; 70 119 } 71 120
Note:
See TracChangeset
for help on using the changeset viewer.
