PApp
view release on metacpan or search on metacpan
PApp/Config.pm view on Meta::CPAN
The username and password to access the state database.
=item CIPHERKEY*
The cipherkey to use to encrypt cookies.
=back
=cut
my $load = sub {
local $@;
do $_[0]
or do {
$@ ||= "$!";
die "$_[0]: $@";
}
};
%PApp::Config = (
ETCDIR => "/etc/papp",
);
$PApp::Config{ETCDIR} = $ENV{PAPP_ETCDIR}
if exists $ENV{PAPP_ETCDIR};
%PApp::Config = (%PApp::Config, %{ $load->("$PApp::Config{ETCDIR}/config") });
eval {
%PApp::Config = (%PApp::Config, %{ $load->("$PApp::Config{ETCDIR}/secure") });
$PApp::Config{SECURE} = 1;
};
our @incpath = $PApp::Config{LIBDIR};
sub search_path {
push @incpath, @_;
@incpath;
}
$PApp::statedb = $PApp::Config{STATEDB};
$PApp::statedb_user = $PApp::Config{STATEDB_USER};
$PApp::statedb_pass = $PApp::Config{STATEDB_PASS};
# "inlined" into DBH
$Database = new PApp::SQL::Database "papp_1", $PApp::statedb, $PApp::statedb_user, $PApp::statedb_pass;
our %prepare_papp_dbh;
sub _prepare_DBH {
my $dbh = shift;
$dbh->do ("set names latin1 collate latin1_nopad_bin");
$PApp::st_fetchstate = $dbh->prepare ("select count, state, userid, previd, sessid from event_count left join state on (id = ?)");
$PApp::st_newstateids = $dbh->prepare ("update state_seq set seq = last_insert_id(seq) + ?");
$PApp::st_insertstate = $dbh->prepare ("replace into state (id, state, userid, previd, sessid, alternative) values (?,?,?,?,?,?)");
$PApp::st_eventcount = $dbh->prepare ("select count from event_count");
$PApp::st_reload_p = $dbh->prepare ("select count(*) from state where previd = ? and alternative = ?");
$PApp::st_newuserid = $dbh->prepare ("update user_seq set seq = last_insert_id(seq) + 1");
$PApp::st_replacepref = $dbh->prepare ("replace into prefs (uid, path, name, value) values (?,?,?,?)");
$PApp::st_deletepref = $dbh->prepare ("delete from prefs where uid = ? and path = ? and name = ?");
$_->($dbh) for values %prepare_papp_dbh;
}
sub new_dbh {
my $id = shift || "papp_1";
PApp::SQL::connect_cached (
$id,
$PApp::statedb,
$PApp::statedb_user,
$PApp::statedb_pass,
{
AutoCommit => 1,
RaiseError => 1,
PrintError => 0,
@_,
},
\&_prepare_DBH
) or die "error connecting to papp database: $DBI::errstr"
}
sub DBH() {
$DBH ||= new_dbh
}
DBH;
1;
=head1 SEE ALSO
L<PApp>.
=head1 AUTHOR
Marc Lehmann <schmorp@schmorp.de>
=cut
( run in 0.889 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )