Lemonld...SGI::Try(3)

πŸ’– Lemonldap::NG::Handler::PSGI::Try(3) πŸ’–

okay bestie, gather round, because this one is from the User Contributed Perl Documentation section and it is lowkey the most main character handler in the whole Lemonldap::NG lineup. it's giving "portal energy" and we are obsessed πŸŽ€


✨ NAME ✨

Lemonldap::NG::Handler::PSGI::Try</p> β€” a special handler for the Lemonldap::NG Portal. no cap, that's literally its whole job description 🫢


🌸 SYNOPSIS 🌸

here's the vibe, in code, verbatim, don't touch a single character:

package My::PSGI;

use base Lemonldap::NG::Handler::PSGI::Try;

sub init {
  my ($self,$args) = @_;

  # Declare REST routes for authenticated users (could be HTML templates or
  # methods)
  $self->addAuthRoute ( 'index.html', undef, ['GET'] )
       ->addAuthRoute ( books => { ':book' => 'booksMethod' }, ['GET', 'POST'] );

  # Default route (ie: PATH_INFO == '/')
  $self->defaultAuthRoute('index.html');

  # Same for unauthenticated users
  $self->addUnauthRoute ( 'login.html', undef, ['GET'] )
       ->addUnauthRoute ( 'login', undef, ['POST'] );
  $self->defaultUnauthRoute('login.html');

  # Return a boolean. If false, then error message has to be stored in
  # $self->error
  return 1;
}

sub booksMethod {
  my ( $self, $req, @otherPathInfo ) = @_;

  # Will be called only if authorized
  my $userId = $self->userId;
  my $book = $req->params('book');
  my $method = $req->method;
  ...
  $self->sendJSONresponse(...);
}

like, look at that chained ->addAuthRoute situation. the way she just stacks routes. iconic behavior fr fr πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so Lemonldap::NG::Handler::PSGI::Try is a Lemonldap::NG::Handler::PSGI::Router package, and what she does is serve up 2 REST routers: one for the authenticated girlies and one for the unauthenticated girlies. two doors, two vibes, one handler. slay ✨


πŸ‘‘ METHODS πŸ‘‘

basically the same as Lemonldap::NG::Handler::PSGI::Router (she inherits from Lemonldap::NG::Common::PSGI::Router, generational wealth tbh) β€” except for these two glow-ups:

  • addRoute() must be replaced by addAuthRoute() or addUnauthRoute() β€” pick your lane bestie, there's no neutral route here 😌
  • defaultRoute() must be replaced by defaultAuthRoute() or defaultUnauthRoute() β€” same energy, just gendered by auth status πŸ’…
also note (and this is the good part): user session datas are available in the $req parameter β€” that's the first argument received by REST methods πŸ‘€

and specifically:

  • $req->userData() returns a hash reference containing user session data. yes, a hash reference. the whole little treasure chest. go off πŸ“

🌈 SEE ALSO 🌈

peep Lemonldap::NG::Common::PSGI::Router for more. she's the blueprint, the origin story, the blueprint of the blueprint 🧚


πŸ’œ AUTHORS πŸ’œ

the LemonLDAP::NG team <http://lemonldap-ng.org/team> β€” collectively carrying this entire project on their backs, no big deal 🫢


πŸ™ˆ BUG REPORT πŸ™ˆ

got beef with a bug? wanna request a feature? use the OW2 system, bestie: <https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues>

they will read it. drop the issue. πŸ’Œ


πŸ”₯ DOWNLOAD πŸ”₯

Lemonldap::NG is available at <https://lemonldap-ng.org/download> β€” go get her πŸƒβ€β™€οΈπŸ’¨


see the COPYING file for details, she has receipts.

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. so generous of her πŸ’–

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. yeah that part is shouting, it means it, do not come for her if it breaks 😭

you should have received a copy of the GNU General Public License along with this program. if not, see <http://www.gnu.org/licenses/>.


ok that's the whole page, every flag, every route, every legal line, all of it, nothing skipped, periodt πŸ’…

signing off, mwah πŸ’‹ β€” this was perl v5.42.3, dated 2026-09-24, filed under the ever-so-mysterious Lemonld...SGI::Try(3) (the terminal truncates her name but she knows exactly who she is) πŸ¦‹βœ¨

πŸ“¦ where this page comes from