User(3pm)
π User(3pm) β the vibe-y little page about User π
okay so bestie, welcome to User, a Perl module living its best life in the User Contributed Perl Documentation section (that's the 3pm part of User(3pm), iykyk). it's tiny, it's iconic, it does exactly one job and does it slayfully π
β¨ NAME β¨
User β the API for locating user info no matter what OS you're on π¦
like, Windows? Unix? doesn't matter. she finds your people. periodt.
β¨ SYNOPSIS β¨
here's the whole vibe in code form, no cap:
use User;
my $cfg = Config::IniFiles->new
(
-file => sprintf("%s/%s", User->Home, ".ncfg"),
-default => 'Default'
);
print "Your login is ", User->Login, "\n";
look at her go π₯Ή she's literally pulling the home directory, gluing .ncfg onto it with sprintf, and then announcing your login to the world. main character energy fr fr.
β¨ DESCRIPTION β¨
so what is this module even for? it lets applications retrieve per-user characteristics β like, the little details that belong to you specifically, not the machine. that's it. that's the whole thing. lowkey elegant, highkey useful β¨
β¨ METHODS β¨
πΈ Home
returns a location that can be expected to be a user's "Home" directory β and she does it on either Windows or Unix, which is the whole point π
now, one way to write this would've been to check the operating system first and then look in the expected location for an OS of that type. but nope β the author chose to do it like this instead:
sub Home {
return $ENV{HOME} if $ENV{HOME};
return $ENV{USERPROFILE} if $ENV{USERPROFILE};
return "";
}
in other words (bestie, listen up π): if $HOME is defined in the user's environment, that's what gets used. otherwise $USERPROFILE gets used. otherwise you get "" β an empty string, the saddest little return value π
and a contribution for Macintosh (or honestly any other number of OS/arch combinations, the door is wide open) is greatly solicited. like, pls. she's asking nicely. π₯Ίπ«Ά
πΈ Login
returns the login id of the user on either Unix or NT, by checking getlogin, getpwuid, and various environment variables. three sources, one answer, that's the strategy π
β¨
β¨ SEE ALSO β¨
File::HomeDirβ this one seems to be a very well-done update of the same concept as this module. like, the glow-up version π go check her out.
β¨ COPYRIGHT INFO β¨
Copyright: Copyright (c) 2002-2010 Terrence Brannon. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π
License: GPL, Artistic β available in the Debian Linux Distribution at /usr/share/common-licenses/{GPL,Artistic} π§
β¨ AUTHOR β¨
T.M. Brannon, tbone@cpan.org π
and also: "I am grateful for additions by Rob Napier and Malcom Nooning." β shoutout to the collab queens π«Άβ¨
β¨ ACKNOWLEDGEMENTS β¨
the author would like to offer profuse thanks to a fellow perl monk at www.perlmonks.org, the_slycer, who told him where HOME could be found on Windows machines. genuinely a hero, no notes π§π
also big thanks to Bob Armstrong for providing the text of the copyright notice and for including this in the Debian Linux distribution. iconic behaviour, we love to see it π
and finally, the obligatory nod: perl(1). πͺ
and that's the whole page, bestie!! π this was User(3pm) from perl v5.36.0, dated 2022-12-02 β go forth and find your users, you absolute legend πβ¨
π¦ where this page comes from
- debian bookworm: libuser-perl 1.9-1.2
- debian trixie: libuser-perl 1.9-1.2
- ubuntu noble: libuser-perl 1.9-1.2
- ubuntu questing: libuser-perl 1.9-1.2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms