PApp::Env - communicate between processes and the outside.


 use PApp::Env;
 # See also PApp::Prefs and PApp::Session


This module can be used to get and set some kind of "environment" variables shared between all papp applications. When inside a PApp environment (e.g. inside a papp program) this module uses PApp's state database handle. Outside the module it tries to open a connection to the database itself, so it can be used e.g. from shell script to communicate data asynchronously to the module.

If you pass in a reference, the Storable module (Storable) will be used to serialize and deserialize it.

Environment variable names (often referred as key in this document) are treated case-insensitive if the database allows it. The contents will be treated as opaque binary objects (again, if the database supports it).

The only database supported by this module is MySQL, so the above is currently true in all cases.

setenv key => value

Sets a single environment variable to the specified value. (mysql-specific ;)

unsetenv key

Unsets (removes) the specified environment variable.

getenv key

Return the value of the specified environment value

lockenv BLOCK

Locks the environment table against modifications (this is, again, only implemented for mysql so far), while executing the specified block. Returns the return value of BLOCK (which is called in scalar context).

modifyenv BLOCK key

Modifies the specified environment variable atomically by calling code-ref with the value as first argument. The code-reference must modify the argument in-place, e.g.:

   modifyenv { $_[0]++ } "myapp_counter";

The modification will be done atomically. modifyenv returns whatever the BLOCK returned.

@list = listenv

Returns a list of all environment variables (names).


 - should also support a tied hash interface.

 - setenv requires mysql (actually the replace sql command), but it's so
   much easier & faster that way.




 Marc Lehmann <>