Filename | /var/www/foswiki11/lib/Foswiki/If/OP_allows.pm |
Statements | Executed 14 statements in 562µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 25µs | 52µs | new | Foswiki::If::OP_allows::
1 | 1 | 1 | 22µs | 40µs | BEGIN@11 | Foswiki::If::OP_allows::
1 | 1 | 1 | 13µs | 20µs | BEGIN@12 | Foswiki::If::OP_allows::
1 | 1 | 1 | 12µs | 32µs | BEGIN@17 | Foswiki::If::OP_allows::
1 | 1 | 1 | 5µs | 5µs | BEGIN@18 | Foswiki::If::OP_allows::
1 | 1 | 1 | 5µs | 5µs | BEGIN@14 | Foswiki::If::OP_allows::
0 | 0 | 0 | 0s | 0s | evaluate | Foswiki::If::OP_allows::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | =begin TML | ||||
4 | |||||
5 | ---+ package Foswiki::If::OP_allows | ||||
6 | |||||
7 | =cut | ||||
8 | |||||
9 | package Foswiki::If::OP_allows; | ||||
10 | |||||
11 | 2 | 43µs | 2 | 59µs | # spent 40µs (22+18) within Foswiki::If::OP_allows::BEGIN@11 which was called:
# once (22µs+18µs) by Foswiki::If::Parser::new at line 11 # spent 40µs making 1 call to Foswiki::If::OP_allows::BEGIN@11
# spent 18µs making 1 call to strict::import |
12 | 2 | 35µs | 2 | 27µs | # spent 20µs (13+7) within Foswiki::If::OP_allows::BEGIN@12 which was called:
# once (13µs+7µs) by Foswiki::If::Parser::new at line 12 # spent 20µs making 1 call to Foswiki::If::OP_allows::BEGIN@12
# spent 7µs making 1 call to warnings::import |
13 | |||||
14 | 2 | 45µs | 1 | 5µs | # spent 5µs within Foswiki::If::OP_allows::BEGIN@14 which was called:
# once (5µs+0s) by Foswiki::If::Parser::new at line 14 # spent 5µs making 1 call to Foswiki::If::OP_allows::BEGIN@14 |
15 | 1 | 9µs | our @ISA = ('Foswiki::Query::BinaryOP'); | ||
16 | |||||
17 | 2 | 33µs | 2 | 51µs | # spent 32µs (12+19) within Foswiki::If::OP_allows::BEGIN@17 which was called:
# once (12µs+19µs) by Foswiki::If::Parser::new at line 17 # spent 32µs making 1 call to Foswiki::If::OP_allows::BEGIN@17
# spent 19µs making 1 call to Assert::import |
18 | 2 | 369µs | 1 | 5µs | # spent 5µs within Foswiki::If::OP_allows::BEGIN@18 which was called:
# once (5µs+0s) by Foswiki::If::Parser::new at line 18 # spent 5µs making 1 call to Foswiki::If::OP_allows::BEGIN@18 |
19 | |||||
20 | # spent 52µs (25+27) within Foswiki::If::OP_allows::new which was called:
# once (25µs+27µs) by Foswiki::If::Parser::new at line 31 of /var/www/foswiki11/lib/Foswiki/If/Parser.pm | ||||
21 | 1 | 700ns | my $class = shift; | ||
22 | 1 | 24µs | 1 | 27µs | return $class->SUPER::new( name => 'allows', prec => 600 ); # spent 27µs making 1 call to Foswiki::Query::BinaryOP::new |
23 | } | ||||
24 | |||||
25 | sub evaluate { | ||||
26 | my $this = shift; | ||||
27 | my $node = shift; | ||||
28 | my $a = $node->{params}->[0]; # topic name (string) | ||||
29 | my $b = $node->{params}->[1]; # access mode (string) | ||||
30 | my $mode = $b->_evaluate(@_) || 'view'; | ||||
31 | my %domain = @_; | ||||
32 | my $session = $domain{tom}->session; | ||||
33 | throw Error::Simple( | ||||
34 | 'No context in which to evaluate "' . $a->stringify() . '"' ) | ||||
35 | unless $session; | ||||
36 | |||||
37 | my $str = $a->evaluate(@_); | ||||
38 | return 0 unless $str; | ||||
39 | |||||
40 | my ( $web, $topic ) = | ||||
41 | $session->normalizeWebTopicName( $session->{webName}, $str ); | ||||
42 | |||||
43 | my $ok = 0; | ||||
44 | |||||
45 | # Try for an existing topic first. | ||||
46 | if ( $session->topicExists( $web, $topic ) ) { | ||||
47 | |||||
48 | my $topicObject = Foswiki::Meta->new( $session, $web, $topic ); | ||||
49 | $ok = $topicObject->haveAccess($mode); | ||||
50 | } | ||||
51 | |||||
52 | # Not an existing web.topic name, see if the string on its own | ||||
53 | # is a web name | ||||
54 | elsif ( $session->webExists($str) ) { | ||||
55 | my $webObject = Foswiki::Meta->new( $session, $str ); | ||||
56 | $ok = $webObject->haveAccess($mode); | ||||
57 | } | ||||
58 | |||||
59 | # Not an existing web.topic or a web on it's own; maybe it's | ||||
60 | # web.topic for an existing web but non-existing topic | ||||
61 | elsif ( $session->webExists($web) ) { | ||||
62 | my $webObject = Foswiki::Meta->new( $session, $web ); | ||||
63 | $ok = $webObject->haveAccess($mode); | ||||
64 | } | ||||
65 | else { | ||||
66 | $ok = 0; | ||||
67 | } | ||||
68 | return $ok ? 1 : 0; | ||||
69 | } | ||||
70 | |||||
71 | 1 | 4µs | 1; | ||
72 | __END__ |