.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Lemonldap::NG::Common::PSGI 3pm" .TH Lemonldap::NG::Common::PSGI 3pm "2023-05-13" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Lemonldap::NG::Common::PSGI \- Base library for PSGI modules of Lemonldap::NG. Use Lemonldap::NG::Common::PSGI::Router for REST API. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& 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(\*(Aqinfo\*(Aq); \& # It is possible to use syslog for user actions \& $self\->syslog(\*(Aqdaemon\*(Aq); \& \& # 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, [ \*(AqContent\-Type\*(Aq => \*(Aqtext/plain\*(Aq ], [ \*(AqBody lines\*(Aq ] ]; \& } .Ve .PP This package could then be called as a \s-1CGI,\s0 using FastCGI,... .PP .Vb 1 \& #!/usr/bin/env perl \& \& use My::PSGI; \& use Plack::Handler::FCGI; # or Plack::Handler::CGI \& \& Plack::Handler::FCGI\->new\->run( My::PSGI\->run() ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This package provides base class for Lemonldap::NG web interfaces but could be used regardless. .SH "METHODS" .IX Header "METHODS" .SS "Running methods" .IX Subsection "Running methods" \fIrun ( \f(CI$args\fI )\fR .IX Subsection "run ( $args )" .PP Main method that will manage requests. It can be called using class or already created object: .IP "Class\->run($args):" 4 .IX Item "Class->run($args):" launch new($args), \fBinit()\fR, then manage requests (using private \fB_run()\fR method .ie n .IP "$object\->\fBrun()\fR:" 4 .el .IP "\f(CW$object\fR\->\fBrun()\fR:" 4 .IX Item "$object->run():" manage directly requests. Initialization must have be done earlier. .SS "Logging" .IX Subsection "Logging" \fIlmLog ( \f(CI$msg\fI, \f(CI$level\fI)\fR .IX Subsection "lmLog ( $msg, $level)" .PP Print on \s-1STDERR\s0 messages if level > \f(CW$self\fR\->{logLevel}. Defined log levels are: debug, info, notice, warn, error. .PP \fIuserLog ($msg, \f(CI$level\fI)\fR .IX Subsection "userLog ($msg, $level)" .PP Alias for \f(CW$self\fR\->userLogger\->$level($msg). Prefer to use this form (required for Auth/Combination) .PP \fI\f(BIuserError()\fI \f(BIuserNotice()\fI \f(BIuserInfo()\fI\fR .IX Subsection "userError() userNotice() userInfo()" .PP Alias for userLog(level). Note that you must use \f(CW$self\fR\->userLogger\->$level instead .SS "Content sending" .IX Subsection "Content sending" Note that \f(CW$req\fR, the first argument of these functions, is a Lemonldap::NG::Common::PSGI::Request. See the corresponding documentation. .PP \fIsendHtml ( \f(CI$req\fI, \f(CI$template\fI )\fR .IX Subsection "sendHtml ( $req, $template )" .PP This method build \s-1HTML\s0 response using HTML::Template and the template \f(CW$template\fR. \&\f(CW$template\fR file must be in \f(CW$self\fR\->templateDir directory. \&\s-1HTML\s0 template will receive 5 variables: .IP "\s-1SCRIPT_NAME:\s0 the path to the (F)CGI" 4 .IX Item "SCRIPT_NAME: the path to the (F)CGI" .PD 0 .ie n .IP "\s-1STATIC_PREFIX:\s0 content of $self\->staticPrefix" 4 .el .IP "\s-1STATIC_PREFIX:\s0 content of \f(CW$self\fR\->staticPrefix" 4 .IX Item "STATIC_PREFIX: content of $self->staticPrefix" .ie n .IP "\s-1AVAILABLE_LANGUAGES:\s0 content of $self\->languages" 4 .el .IP "\s-1AVAILABLE_LANGUAGES:\s0 content of \f(CW$self\fR\->languages" 4 .IX Item "AVAILABLE_LANGUAGES: content of $self->languages" .ie n .IP "\s-1LINKS: JSON\s0 stringification of $self\->links" 4 .el .IP "\s-1LINKS: JSON\s0 stringification of \f(CW$self\fR\->links" 4 .IX Item "LINKS: JSON stringification of $self->links" .IP "\s-1VERSION:\s0 Lemonldap::NG version" 4 .IX Item "VERSION: Lemonldap::NG version" .PD .PP The response is always send with a 200 code. .PP \fIsendJSONresponse ( \f(CI$req\fI, \f(CI$json\fI, \f(CI%args\fI )\fR .IX Subsection "sendJSONresponse ( $req, $json, %args )" .PP Stringify \f(CW$json\fR object and send it to the client. \f(CW$req\fR is the Lemonldap::NG::Common::PSGI::Request object; \f(CW%args\fR can define the \s-1HTTP\s0 error code (200 by default) or headers to add. .PP If client is not json compatible (`Accept` header), response is send in \s-1XML.\s0 .PP Examples: .PP .Vb 1 \& $self\->sendJSONresponse ( $req, { result => 0 }, code => 400 ); \& \& $self\->sendJSONresponse ( $req, { result => 1 } ); \& \& $self\->sendJSONresponse ( $req, { result => 1 }, headers => [ X => Z ] ); .Ve .PP \fIsendError ( \f(CI$req\fI, \f(CI$msg\fI, \f(CI$code\fI )\fR .IX Subsection "sendError ( $req, $msg, $code )" .PP Call sendJSONresponse with `{ error => \f(CW$msg\fR }` and code (default to 500) and call \fBlmLog()\fR to duplicate error in logs .PP \fIabort ( \f(CI$msg\fI )\fR .IX Subsection "abort ( $msg )" .PP When an error is detected during startup (\fBinit()\fR sub), you must not call \&\fBsendError()\fR but call \fBabort()\fR. Each request received later will receive the error (abort uses \fBsendError()\fR behind the scene). .SS "Accessors" .IX Subsection "Accessors" \fIerror\fR .IX Subsection "error" .PP String error. Used if \fBinit()\fR fails or if sendError is called without argument. .PP \fIlanguages\fR .IX Subsection "languages" .PP String containing list of languages (ie "fr, en'). Used by \fBsendHtml()\fR. .PP \fIlogLevel\fR .IX Subsection "logLevel" .PP See \fBlmLog()\fR. .PP \fIstaticPrefix\fR .IX Subsection "staticPrefix" .PP String indicating the path of static content (js, css,...). Used by \fBsendHtml()\fR. .PP \fItemplateDir\fR .IX Subsection "templateDir" .PP Directory containing template files. .PP \fIlinks\fR .IX Subsection "links" .PP Array of links to display by \fBsendHtml()\fR. Each element has the form: .PP .Vb 1 \& { target => \*(Aqhttp://target\*(Aq, title => \*(Aqstring to display\*(Aq } .Ve .PP \fIsyslog\fR .IX Subsection "syslog" .PP Syslog facility. If empty, \s-1STDERR\s0 will be used for logging .SH "SEE ALSO" .IX Header "SEE ALSO" , Lemonldap::NG::Portal, Lemonldap::NG::Handler, Plack, \s-1PSGI\s0, Lemonldap::NG::Common::PSGI::Router, Lemonldap::NG::Common::PSGI::Request, HTML::Template, .SH "AUTHORS" .IX Header "AUTHORS" .IP "LemonLDAP::NG team " 4 .IX Item "LemonLDAP::NG team " .SH "BUG REPORT" .IX Header "BUG REPORT" Use \s-1OW2\s0 system to report bug or ask for features: .SH "DOWNLOAD" .IX Header "DOWNLOAD" Lemonldap::NG is available at .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" See \s-1COPYING\s0 file for details. .PP This library is free software; you can redistribute it and/or modify it under the terms of the \s-1GNU\s0 General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. .PP This program is distributed in the hope that it will be useful, but \s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of \&\s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE.\s0 See the \&\s-1GNU\s0 General Public License for more details. .PP You should have received a copy of the \s-1GNU\s0 General Public License along with this program. If not, see .