logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

User - API for locating user information regardless of OS

Acknowledgements

       I would like to offer profuse thanks to my fellow perl monk at www.perlmonks.org, the_slycer, who told me
       where HOME could be found on Windows machines.

       I would also like to thank Bob Armstrong for providing me with the text of the copyright notice  and  for
       including this in the Debian Linux distribution.

       perl(1).

perl v5.36.0                                       2022-12-02                                          User(3pm)

Author

       T.M. Brannon, tbone@cpan.org

       I am grateful for additions by Rob Napier and Malcom Nooning.

Description

       This module is allows applications to retrieve per-user characteristics.

Methods

       Home
           Returns a location that can be expected to be a users "Home" directory on either Windows or Unix.

           While  one  way  of  writing  this would be to check for operating system and then check the expected
           location for an operation system of that type, I chose to do the following:

            sub Home {

             return $ENV{HOME}        if $ENV{HOME};
             return $ENV{USERPROFILE} if $ENV{USERPROFILE};
             return  "";

            }

           In other words, if $HOME is  defined  in  the  user's  environment,  then  that  is  used.  Otherwise
           $USERPROFILE is used. Otherwise "" is returned.

           A contribution for Macintosh (or any other number of OS/arch combinations) is greatly solicited.

       Login
           Returns  login  id  of  user  on  either  Unix  or NT by checking "getlogin", "getpwuid", and various
           environment variables.

Name

       User - API for locating user information regardless of OS

See Also

       File::HomeDir seems to be a very well-done update of the same concept as this module.

Synopsis

         use User;

         my $cfg = Config::IniFiles->new
               (
                 -file    => sprintf("%s/%s", User->Home, ".ncfg"),
                 -default => 'Default'
               );

         print "Your login is ", User->Login, "\n";

See Also