File: User.pm

package info (click to toggle)
libuser-perl 1.9-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch, wheezy
  • size: 52 kB
  • ctags: 4
  • sloc: makefile: 37; perl: 26
file content (117 lines) | stat: -rw-r--r-- 2,527 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package User;

use strict;

use vars qw(@ISA $VERSION);

$VERSION = '1.9';


# Preloaded methods go here.

sub Home {

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

}

sub Login {
    return getlogin || getpwuid( $< ) || $ENV{ LOGNAME } || $ENV{ USER } ||
        $ENV{ USERNAME } || 'unknown';
}

1;
__END__
# Below is stub documentation for your module. You better edit it!

=head1 NAME

User - API for locating user information regardless of OS

=head1 SYNOPSIS

  use User;

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

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

=head1 DESCRIPTION

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

=head1 METHODS

=over 4

=item 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.

=item Login

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

=back

=head1 SEE ALSO

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


=head1 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}

=head1 AUTHOR

T.M. Brannon, tbone@cpan.org

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


=head1 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).

=cut