Filename | /var/www/foswikidev/core/lib/Foswiki/Query/OP_ref.pm |
Statements | Executed 18 statements in 510µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 1 | 1 | 34µs | 49µs | new | Foswiki::Query::OP_ref::
1 | 1 | 1 | 13µs | 25µs | BEGIN@11 | Foswiki::Query::OP_ref::
1 | 1 | 1 | 10µs | 34µs | BEGIN@17 | Foswiki::Query::OP_ref::
1 | 1 | 1 | 10µs | 14µs | BEGIN@12 | Foswiki::Query::OP_ref::
1 | 1 | 1 | 8µs | 111µs | BEGIN@16 | Foswiki::Query::OP_ref::
1 | 1 | 1 | 4µs | 4µs | BEGIN@13 | Foswiki::Query::OP_ref::
0 | 0 | 0 | 0s | 0s | __ANON__[:60] | Foswiki::Query::OP_ref::
0 | 0 | 0 | 0s | 0s | __ANON__[:63] | Foswiki::Query::OP_ref::
0 | 0 | 0 | 0s | 0s | evaluate | Foswiki::Query::OP_ref::
0 | 0 | 0 | 0s | 0s | evaluatesToConstant | Foswiki::Query::OP_ref::
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::Query::OP_ref | ||||
6 | |||||
7 | =cut | ||||
8 | |||||
9 | package Foswiki::Query::OP_ref; | ||||
10 | |||||
11 | 2 | 29µs | 2 | 37µs | # spent 25µs (13+12) within Foswiki::Query::OP_ref::BEGIN@11 which was called:
# once (13µs+12µs) by Foswiki::Query::Parser::BEGIN@58 at line 11 # spent 25µs making 1 call to Foswiki::Query::OP_ref::BEGIN@11
# spent 12µs making 1 call to strict::import |
12 | 2 | 23µs | 2 | 18µs | # spent 14µs (10+4) within Foswiki::Query::OP_ref::BEGIN@12 which was called:
# once (10µs+4µs) by Foswiki::Query::Parser::BEGIN@58 at line 12 # spent 14µs making 1 call to Foswiki::Query::OP_ref::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | 2 | 33µs | 1 | 4µs | # spent 4µs within Foswiki::Query::OP_ref::BEGIN@13 which was called:
# once (4µs+0s) by Foswiki::Query::Parser::BEGIN@58 at line 13 # spent 4µs making 1 call to Foswiki::Query::OP_ref::BEGIN@13 |
14 | 1 | 6µs | our @ISA = ('Foswiki::Query::OP'); | ||
15 | |||||
16 | 2 | 29µs | 2 | 214µs | # spent 111µs (8+103) within Foswiki::Query::OP_ref::BEGIN@16 which was called:
# once (8µs+103µs) by Foswiki::Query::Parser::BEGIN@58 at line 16 # spent 111µs making 1 call to Foswiki::Query::OP_ref::BEGIN@16
# spent 103µs making 1 call to Error::import |
17 | 2 | 355µs | 2 | 58µs | # spent 34µs (10+24) within Foswiki::Query::OP_ref::BEGIN@17 which was called:
# once (10µs+24µs) by Foswiki::Query::Parser::BEGIN@58 at line 17 # spent 34µs making 1 call to Foswiki::Query::OP_ref::BEGIN@17
# spent 24µs making 1 call to Exporter::import |
18 | |||||
19 | # spent 49µs (34+14) within Foswiki::Query::OP_ref::new which was called 3 times, avg 16µs/call:
# 3 times (34µs+14µs) by Foswiki::Query::Parser::new at line 112 of /var/www/foswikidev/core/lib/Foswiki/Query/Parser.pm, avg 16µs/call | ||||
20 | 3 | 1µs | my $class = shift; | ||
21 | 3 | 30µs | 3 | 14µs | return $class->SUPER::new( arity => 2, name => '/', prec => 800 ); # spent 14µs making 3 calls to Foswiki::Query::OP::new, avg 5µs/call |
22 | } | ||||
23 | |||||
24 | sub evaluate { | ||||
25 | my $this = shift; | ||||
26 | my $pnode = shift; | ||||
27 | my %domain = @_; | ||||
28 | |||||
29 | eval "require $Foswiki::cfg{Store}{QueryAlgorithm}"; | ||||
30 | die $@ if $@; | ||||
31 | |||||
32 | my $a = $pnode->{params}[0]; | ||||
33 | my $node = $a->evaluate(@_); | ||||
34 | return unless defined $node; | ||||
35 | if ( ref($node) eq 'HASH' ) { | ||||
36 | return; | ||||
37 | } | ||||
38 | if ( !( ref($node) eq 'ARRAY' ) ) { | ||||
39 | $node = [$node]; | ||||
40 | } | ||||
41 | my @result; | ||||
42 | foreach my $v (@$node) { | ||||
43 | |||||
44 | # Has to be relative to the web of the topic we are querying | ||||
45 | my ( $w, $t ) = | ||||
46 | $Foswiki::Plugins::SESSION->normalizeWebTopicName( | ||||
47 | $Foswiki::Plugins::SESSION->{webName}, $v ); | ||||
48 | try { | ||||
49 | my $submeta = | ||||
50 | $Foswiki::cfg{Store}{QueryAlgorithm} | ||||
51 | ->getRefTopic( $domain{tom}, $w, $t ); | ||||
52 | my $b = $pnode->{params}[1]; | ||||
53 | my $res = $b->evaluate( tom => $submeta, data => $submeta ); | ||||
54 | if ( ref($res) eq 'ARRAY' ) { | ||||
55 | push( @result, @$res ); | ||||
56 | } | ||||
57 | else { | ||||
58 | push( @result, $res ); | ||||
59 | } | ||||
60 | } | ||||
61 | catch Error with { | ||||
62 | print STDERR "ERROR IN OP_ref: $_[0]->{-text}" if DEBUG; | ||||
63 | }; | ||||
64 | } | ||||
65 | return unless scalar(@result); | ||||
66 | return $result[0] if scalar(@result) == 1; | ||||
67 | return \@result; | ||||
68 | } | ||||
69 | |||||
70 | sub evaluatesToConstant { | ||||
71 | my $this = shift; | ||||
72 | my $node = shift; | ||||
73 | return 1 if $node->{params}[0]->evaluatesToConstant(@_); | ||||
74 | |||||
75 | # param[1] may contain non-constant terms, but that's OK because | ||||
76 | # they are evaluated relative to the (constant) param[0] | ||||
77 | return 0; | ||||
78 | } | ||||
79 | |||||
80 | 1 | 3µs | 1; | ||
81 | __END__ |