Lemonld...on::PSGI(3)
π Lemonldap::NG::Common::PSGI β the manual, but make it cute π
okay bestie, gather round, because this is Lemonldap::NG::Common::PSGI, a User Contributed Perl Documentation classic, and it's the base library for all the PSGI modules of Lemonldap::NG. β¨ And listen β if you're here for a REST API specifically, the page itself says: use Lemonldap::NG::Common::PSGI::Router instead. iykyk. π
πΈ NAME πΈ
Lemonldap::NG::Common::PSGI β base library for PSGI modules of Lemonldap::NG. Use Lemonldap::NG::Common::PSGI::Router for REST API.
β¨ SYNOPSIS β¨
so here's the whole vibe, verbatim, no cap:
package My::PSGI;
use base Lemonldap::NG::Common::PSGI;
sub init {
my ($self,$args) = @_;
# Will be called 1 time during startup
# Store debug level
$self->logLevel('info');
# It is possible to use syslog for user actions
$self->syslog('daemon');
# Return a boolean. If false, then error message has to be stored in
# $self->error
return 1;
}
sub handler {
my ( $self, $req ) = @_;
# Do something and return a PSGI response
# NB: $req is a Lemonldap::NG::Common::PSGI::Request object
return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Body lines' ] ];
}
and then this package could be called as a CGI, using FastCGI,... like:
#!/usr/bin/env perl
use My::PSGI;
use Plack::Handler::FCGI; # or Plack::Handler::CGI
Plack::Handler::FCGI->new->run( My::PSGI->run() );
π¦ DESCRIPTION π¦
This package provides base class for Lemonldap::NG web interfaces but could be used regardless. fr fr, it doesn't gatekeep β it'll work for your stuff too. π
π METHODS π
π Running methods π
run ( $args )β the main method that will manage requests. It can be called using class or already created object:Class->run($args)β launchnew($args),init(), then manage requests (using private_run()method$object->run()β manage directly requests. Initialization must have be done earlier.
π Logging π
lmLog ( $msg, $level)β Print on STDERR messages if level >$self->{logLevel}. Defined log levels are:debug,info,notice,warn,error.userLog ($msg, $level)β Alias for$self->userLogger->$level($msg). Prefer to use this form (required for Auth/Combination)userError()userNotice()userInfo()β Alias foruserLog(level). Note that you must use$self->userLogger->$levelinstead
π Content sending π
heads up bestie:$req, the first argument of these functions, is aLemonldap::NG::Common::PSGI::Request. See the corresponding documentation.
sendHtml ( $req, $template )β This method build HTML response usingHTML::Templateand the template$template.$templatefile must be in$self->templateDirdirectory. HTML template will receive 5 variables:SCRIPT_NAME: the path to the (F)CGISTATIC_PREFIX: content of$self->staticPrefixAVAILABLE_LANGUAGES: content of$self->languagesLINKS: JSON stringification of$self->linksVERSION: Lemonldap::NG version
The response is always send with a 200 code. periodt. π
sendJSONresponse ( $req, $json, %args )β Stringify$jsonobject and send it to the client.$reqis theLemonldap::NG::Common::PSGI::Requestobject;%argscan define the HTTP error code (200 by default) or headers to add.
If client is not json compatible (Accept header), response is send in XML.
Examples:
$self->sendJSONresponse ( $req, { result => 0 }, code => 400 );
$self->sendJSONresponse ( $req, { result => 1 } );
$self->sendJSONresponse ( $req, { result => 1 }, headers => [ X => Z ] );
sendError ( $req, $msg, $code )β CallsendJSONresponsewith{ error => $msg }and code (default to 500) and calllmLog()to duplicate error in logsabort ( $msg )β When an error is detected during startup (init()sub), you must not callsendError()but callabort(). Each request received later will receive the error (abortusessendError()behind the scene).
π§ Accessors π§
errorβ String error. Used ifinit()fails or ifsendErroris called without argument.languagesβ String containing list of languages (ie "fr, en'). Used bysendHtml().logLevelβ SeelmLog().staticPrefixβ String indicating the path of static content (js, css,...). Used bysendHtml().templateDirβ Directory containing template files.linksβ Array of links to display bysendHtml(). Each element has the form:
{ target => 'http://target', title => 'string to display' }
syslogβ Syslog facility. If empty, STDERR will be used for logging
π₯ SEE ALSO π₯
- <http://lemonldap-ng.org/>
Lemonldap::NG::PortalLemonldap::NG::HandlerPlackPSGILemonldap::NG::Common::PSGI::RouterLemonldap::NG::Common::PSGI::RequestHTML::Template
π AUTHORS π
LemonLDAP::NG team <http://lemonldap-ng.org/team> β iconic, honestly. π
π BUG REPORT π
Use OW2 system to report bug or ask for features: <https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues>
β DOWNLOAD β
Lemonldap::NG is available at <https://lemonldap-ng.org/download>
π COPYRIGHT AND LICENSE π
See COPYING file for details.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
and that's the whole thing, bestie β this page came from perl v5.42.3, dated 2026-09-24, and it's living under the name Lemonld...on::PSGI(3). slay π
β¨
π¦ where this page comes from
- fedora 43: lemonldap-ng-common 2.23.4-1.fc43 Β· GPL-2.0-or-later AND MIT AND GPL-3.0-or-later AND OFL-1.1-RFN
- fedora 44: lemonldap-ng-common 2.23.4-1.fc44 Β· GPL-2.0-or-later AND MIT AND GPL-3.0-or-later AND OFL-1.1-RFN
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms