Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/WebFilter.pm |
Statements | Executed 32 statements in 892µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 3 | 1 | 178µs | 303µs | new | Foswiki::WebFilter::
12 | 1 | 1 | 90µs | 90µs | CORE:regcomp (opcode) | Foswiki::WebFilter::
1 | 1 | 1 | 42µs | 63µs | BEGIN@5 | Foswiki::WebFilter::
12 | 1 | 1 | 35µs | 35µs | CORE:match (opcode) | Foswiki::WebFilter::
1 | 1 | 1 | 24µs | 32µs | BEGIN@4 | Foswiki::WebFilter::
0 | 0 | 0 | 0s | 0s | ok | Foswiki::WebFilter::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | package Foswiki::WebFilter; | ||||
3 | |||||
4 | 2 | 46µs | 2 | 39µs | # spent 32µs (24+7) within Foswiki::WebFilter::BEGIN@4 which was called:
# once (24µs+7µs) by Foswiki::Search::BEGIN@24 at line 4 # spent 32µs making 1 call to Foswiki::WebFilter::BEGIN@4
# spent 7µs making 1 call to strict::import |
5 | 2 | 507µs | 2 | 83µs | # spent 63µs (42+20) within Foswiki::WebFilter::BEGIN@5 which was called:
# once (42µs+20µs) by Foswiki::Search::BEGIN@24 at line 5 # spent 63µs making 1 call to Foswiki::WebFilter::BEGIN@5
# spent 20µs making 1 call to warnings::import |
6 | |||||
7 | #TODO: documentme | ||||
8 | #TODO: should this be converted to a FilterIterator? | ||||
9 | |||||
10 | # spec in the $filter, | ||||
11 | # which may include one of: | ||||
12 | # 1 'user' (for only user webs) | ||||
13 | # 2 'template' (for only template webs) | ||||
14 | # $filter may also contain the word 'public' which will further filter | ||||
15 | # webs on whether NOSEARCHALL is specified for them or not. | ||||
16 | # 'allowed' filters out webs that the user is denied access to by a *WEBVIEW. | ||||
17 | |||||
18 | sub new { | ||||
19 | 12 | 55µs | my ( $class, $filter ) = @_; | ||
20 | my $this = bless( {}, $class ); | ||||
21 | foreach my $f (qw(user template public allowed)) { | ||||
22 | 12 | 256µs | 24 | 126µs | $this->{$f} = ( $filter =~ /\b$f\b/ ); # spent 90µs making 12 calls to Foswiki::WebFilter::CORE:regcomp, avg 8µs/call
# spent 35µs making 12 calls to Foswiki::WebFilter::CORE:match, avg 3µs/call |
23 | } | ||||
24 | return $this; | ||||
25 | } | ||||
26 | |||||
27 | sub ok { | ||||
28 | my ( $this, $session, $web ) = @_; | ||||
29 | |||||
30 | return 0 if $this->{template} && $web !~ /(?:^_|\/_)/; | ||||
31 | |||||
32 | return 1 if ( $web eq $session->{webName} ); | ||||
33 | |||||
34 | return 0 if $this->{user} && $web =~ /(?:^_|\/_)/; | ||||
35 | |||||
36 | return 0 if !$session->webExists($web); | ||||
37 | |||||
38 | my $webObject = Foswiki::Meta->new( $session, $web ); | ||||
39 | my $thisWebNoSearchAll = | ||||
40 | Foswiki::isTrue( $webObject->getPreference('NOSEARCHALL') ); | ||||
41 | |||||
42 | return 0 | ||||
43 | if $this->{public} | ||||
44 | && !$session->{users}->isAdmin( $session->{user} ) | ||||
45 | && $thisWebNoSearchAll; | ||||
46 | |||||
47 | return 0 if $this->{allowed} && !$webObject->haveAccess('VIEW'); | ||||
48 | |||||
49 | return 1; | ||||
50 | } | ||||
51 | |||||
52 | 1 | 8µs | 1 | 126µs | our $public = new Foswiki::WebFilter('public'); # spent 126µs making 1 call to Foswiki::WebFilter::new |
53 | 1 | 6µs | 1 | 89µs | our $user = new Foswiki::WebFilter('user'); # spent 89µs making 1 call to Foswiki::WebFilter::new |
54 | 1 | 6µs | 1 | 89µs | our $user_allowed = new Foswiki::WebFilter('user,allowed'); # spent 89µs making 1 call to Foswiki::WebFilter::new |
55 | |||||
56 | 1 | 8µs | 1; | ||
57 | __END__ | ||||
# spent 35µs within Foswiki::WebFilter::CORE:match which was called 12 times, avg 3µs/call:
# 12 times (35µs+0s) by Foswiki::WebFilter::new at line 22, avg 3µs/call | |||||
# spent 90µs within Foswiki::WebFilter::CORE:regcomp which was called 12 times, avg 8µs/call:
# 12 times (90µs+0s) by Foswiki::WebFilter::new at line 22, avg 8µs/call |