Filename | /var/www/foswiki11/lib/Foswiki/Macros/USERINFO.pm |
Statements | Executed 183 statements in 1.97ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
9 | 3 | 3 | 258µs | 669µs | USERINFO | Foswiki::
9 | 1 | 1 | 141µs | 335µs | _USERINFO_token | Foswiki::
5 | 1 | 1 | 51µs | 70µs | __ANON__[:36] | Foswiki::
1 | 1 | 1 | 35µs | 60µs | BEGIN@4.68 | Foswiki::
2 | 1 | 1 | 25µs | 63µs | __ANON__[:45] | Foswiki::
1 | 1 | 1 | 24µs | 63µs | BEGIN@6 | Foswiki::
2 | 1 | 1 | 24µs | 36µs | __ANON__[:20] | Foswiki::
1 | 1 | 1 | 20µs | 29µs | BEGIN@5.69 | Foswiki::
0 | 0 | 0 | 0s | 0s | __ANON__[:28] | Foswiki::
0 | 0 | 0 | 0s | 0s | __ANON__[:51] | Foswiki::
0 | 0 | 0 | 0s | 0s | __ANON__[:65] | Foswiki::
0 | 0 | 0 | 0s | 0s | __ANON__[:73] | Foswiki::
0 | 0 | 0 | 0s | 0s | __ANON__[:81] | Foswiki::
0 | 0 | 0 | 0s | 0s | __ANON__[:86] | Foswiki::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | package Foswiki; | ||||
3 | |||||
4 | 2 | 53µs | 2 | 84µs | # spent 60µs (35+25) within Foswiki::BEGIN@4.68 which was called:
# once (35µs+25µs) by Foswiki::_expandMacroOnTopicRendering at line 4 # spent 60µs making 1 call to Foswiki::BEGIN@4.68
# spent 25µs making 1 call to strict::import |
5 | 2 | 47µs | 2 | 38µs | # spent 29µs (20+9) within Foswiki::BEGIN@5.69 which was called:
# once (20µs+9µs) by Foswiki::_expandMacroOnTopicRendering at line 5 # spent 29µs making 1 call to Foswiki::BEGIN@5.69
# spent 9µs making 1 call to warnings::import |
6 | 2 | 1.36ms | 2 | 103µs | # spent 63µs (24+39) within Foswiki::BEGIN@6 which was called:
# once (24µs+39µs) by Foswiki::_expandMacroOnTopicRendering at line 6 # spent 63µs making 1 call to Foswiki::BEGIN@6
# spent 39µs making 1 call to Assert::import |
7 | |||||
8 | # Set to true if user details should be cloaked. Selected tokens will return an empty string. | ||||
9 | 1 | 900ns | my $USERINFO_cloak = 0; | ||
10 | |||||
11 | my %USERINFO_tokens = ( | ||||
12 | # spent 36µs (24+13) within Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/USERINFO.pm:20] which was called 2 times, avg 18µs/call:
# 2 times (24µs+13µs) by Foswiki::_USERINFO_token at line 139, avg 18µs/call | ||||
13 | 2 | 2µs | my ( $this, $user ) = @_; | ||
14 | 2 | 500ns | return '' if ($USERINFO_cloak); | ||
15 | |||||
16 | 2 | 9µs | 2 | 13µs | my $username = $this->{users}->getLoginName($user); # spent 13µs making 2 calls to Foswiki::Users::getLoginName, avg 6µs/call |
17 | 2 | 700ns | $username = 'unknown' unless defined $username; | ||
18 | |||||
19 | 2 | 10µs | return $username; | ||
20 | }, | ||||
21 | |||||
22 | # Item2466: There is some usage of this undocumented token in VariableTests | ||||
23 | cUID => sub { | ||||
24 | my ( $this, $user ) = @_; | ||||
25 | |||||
26 | return '' if ($USERINFO_cloak); | ||||
27 | return $user; | ||||
28 | }, | ||||
29 | # spent 70µs (51+19) within Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/USERINFO.pm:36] which was called 5 times, avg 14µs/call:
# 5 times (51µs+19µs) by Foswiki::_USERINFO_token at line 139, avg 14µs/call | ||||
30 | 5 | 5µs | my ( $this, $user ) = @_; | ||
31 | 5 | 15µs | 5 | 19µs | my $wikiname = $this->{users}->getWikiName($user); # spent 19µs making 5 calls to Foswiki::Users::getWikiName, avg 4µs/call |
32 | |||||
33 | 5 | 1µs | $wikiname = 'UnknownUser' unless defined $wikiname; | ||
34 | |||||
35 | 5 | 21µs | return $wikiname; | ||
36 | }, | ||||
37 | # spent 63µs (25+38) within Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/USERINFO.pm:45] which was called 2 times, avg 32µs/call:
# 2 times (25µs+38µs) by Foswiki::_USERINFO_token at line 139, avg 32µs/call | ||||
38 | 2 | 2µs | my ( $this, $user ) = @_; | ||
39 | 2 | 12µs | 2 | 38µs | my $wikiusername = $this->{users}->webDotWikiName($user); # spent 38µs making 2 calls to Foswiki::Users::webDotWikiName, avg 19µs/call |
40 | |||||
41 | 2 | 500ns | $wikiusername = "$Foswiki::cfg{UsersWebName}.UnknownUser" | ||
42 | unless defined $wikiusername; | ||||
43 | |||||
44 | 2 | 10µs | return $wikiusername; | ||
45 | }, | ||||
46 | emails => sub { | ||||
47 | my ( $this, $user ) = @_; | ||||
48 | |||||
49 | return '' if ($USERINFO_cloak); | ||||
50 | return join( ', ', $this->{users}->getEmails($user) ); | ||||
51 | }, | ||||
52 | groups => sub { | ||||
53 | my ( $this, $user ) = @_; | ||||
54 | my @groupNames; | ||||
55 | return '' if ($USERINFO_cloak); | ||||
56 | |||||
57 | my $it = $this->{users}->eachMembership($user); | ||||
58 | |||||
59 | while ( $it->hasNext() ) { | ||||
60 | my $group = $it->next(); | ||||
61 | push( @groupNames, $group ); | ||||
62 | } | ||||
63 | |||||
64 | return join( ', ', @groupNames ); | ||||
65 | }, | ||||
66 | |||||
67 | # Item2466: $admin was re-documented as $isadmin November 2011, do not remove | ||||
68 | admin => sub { | ||||
69 | my ( $this, $user ) = @_; | ||||
70 | |||||
71 | return '' if ($USERINFO_cloak); | ||||
72 | return $this->{users}->isAdmin($user) ? 'true' : 'false'; | ||||
73 | }, | ||||
74 | |||||
75 | # Item2466: $isadmin & $isgroup added November 2011 | ||||
76 | isadmin => sub { | ||||
77 | my ( $this, $user ) = @_; | ||||
78 | |||||
79 | return '' if ($USERINFO_cloak); | ||||
80 | return $this->{users}->isAdmin($user) ? 'true' : 'false'; | ||||
81 | }, | ||||
82 | isgroup => sub { | ||||
83 | my ( $this, $user ) = @_; | ||||
84 | |||||
85 | return $this->{users}->isGroup($user) ? 'true' : 'false'; | ||||
86 | } | ||||
87 | 1 | 53µs | ); | ||
88 | 1 | 7µs | my $USERINFO_tokenregex = join( '|', keys %USERINFO_tokens ); | ||
89 | |||||
90 | # spent 669µs (258+411) within Foswiki::USERINFO which was called 9 times, avg 74µs/call:
# 5 times (100µs+186µs) by Foswiki::WIKINAME at line 15 of /var/www/foswiki11/lib/Foswiki/Macros/WIKINAME.pm, avg 57µs/call
# 2 times (108µs+136µs) by Foswiki::WIKIUSERNAME at line 15 of /var/www/foswiki11/lib/Foswiki/Macros/WIKIUSERNAME.pm, avg 122µs/call
# 2 times (51µs+88µs) by Foswiki::USERNAME at line 16 of /var/www/foswiki11/lib/Foswiki/Macros/USERNAME.pm, avg 70µs/call | ||||
91 | 9 | 6µs | my ( $this, $params ) = @_; | ||
92 | 9 | 7µs | my $format = $params->{format} || '$username, $wikiusername, $emails'; | ||
93 | 9 | 7µs | my $user = $this->{user}; | ||
94 | 9 | 3µs | my $info = $format; | ||
95 | |||||
96 | 9 | 7µs | if ( $params->{_DEFAULT} ) { | ||
97 | $user = $params->{_DEFAULT}; | ||||
98 | return '' if !$user; | ||||
99 | |||||
100 | # map wikiname to a login name | ||||
101 | my $cuid = $this->{users}->getCanonicalUserID($user); | ||||
102 | if ( !$cuid ) { | ||||
103 | |||||
104 | # Failed to get a cUID: if it's a group, leave $user alone | ||||
105 | if ( !$this->{users}->isGroup($user) ) { | ||||
106 | return ''; | ||||
107 | } | ||||
108 | } | ||||
109 | else { | ||||
110 | $user = $cuid; | ||||
111 | } | ||||
112 | return '' unless $user; | ||||
113 | |||||
114 | $USERINFO_cloak = | ||||
115 | ( $Foswiki::cfg{AntiSpam}{HideUserDetails} | ||||
116 | && !$this->{users}->isAdmin( $this->{user} ) | ||||
117 | && $user ne $this->{user} ); | ||||
118 | } | ||||
119 | else { | ||||
120 | 9 | 5µs | $USERINFO_cloak = 0; | ||
121 | } | ||||
122 | |||||
123 | 9 | 2µs | return '' unless $user; | ||
124 | |||||
125 | 18 | 154µs | 9 | 335µs | $info =~ s/\$($USERINFO_tokenregex)/$this->_USERINFO_token($1, $user)/ge; # spent 335µs making 9 calls to Foswiki::_USERINFO_token, avg 37µs/call |
126 | 9 | 27µs | 9 | 76µs | $info = Foswiki::expandStandardEscapes($info); # spent 76µs making 9 calls to Foswiki::expandStandardEscapes, avg 8µs/call |
127 | |||||
128 | 9 | 42µs | return $info; | ||
129 | } | ||||
130 | |||||
131 | # spent 335µs (141+194) within Foswiki::_USERINFO_token which was called 9 times, avg 37µs/call:
# 9 times (141µs+194µs) by Foswiki::USERINFO at line 125, avg 37µs/call | ||||
132 | 9 | 15µs | my ( $this, $token, $user ) = @_; | ||
133 | |||||
134 | 9 | 14µs | 9 | 14µs | ASSERT($token) if DEBUG; # spent 14µs making 9 calls to Assert::ASSERTS_OFF, avg 2µs/call |
135 | 9 | 12µs | 9 | 9µs | ASSERT( ref( $USERINFO_tokens{$token} ) eq 'CODE', # spent 9µs making 9 calls to Assert::ASSERTS_OFF, avg 1µs/call |
136 | "No code for token '$token'" ) | ||||
137 | if DEBUG; | ||||
138 | |||||
139 | 9 | 50µs | 9 | 170µs | return $USERINFO_tokens{$token}->( $this, $user ); # spent 70µs making 5 calls to Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/USERINFO.pm:36], avg 14µs/call
# spent 63µs making 2 calls to Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/USERINFO.pm:45], avg 32µs/call
# spent 36µs making 2 calls to Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/USERINFO.pm:20], avg 18µs/call |
140 | } | ||||
141 | |||||
142 | 1 | 10µs | 1; | ||
143 | __END__ |