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