Filename | /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/OP.pm |
Statements | Executed 211 statements in 2.44ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
91 | 15 | 15 | 1.35ms | 1.35ms | new | Foswiki::Query::OP::
24 | 2 | 2 | 268µs | 395µs | isNumber | Foswiki::Query::OP::
24 | 1 | 1 | 127µs | 127µs | CORE:match (opcode) | Foswiki::Query::OP::
1 | 1 | 1 | 26µs | 33µs | BEGIN@16 | Foswiki::Query::OP::
1 | 1 | 1 | 16µs | 33µs | BEGIN@17 | Foswiki::Query::OP::
0 | 0 | 0 | 0s | 0s | collect | Foswiki::Query::OP::
0 | 0 | 0 | 0s | 0s | evaluate | Foswiki::Query::OP::
0 | 0 | 0 | 0s | 0s | evaluatesToConstant | Foswiki::Query::OP::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | package Foswiki::Query::OP; | ||||
3 | |||||
4 | =begin TML | ||||
5 | |||||
6 | ---+ package Foswiki::Query::OP | ||||
7 | Base class of operators used in queries. Operators are singleton | ||||
8 | objects that specify the parser behaviour and are attached to | ||||
9 | nodes in the parse tree to provide semantics for the nodes. | ||||
10 | |||||
11 | See Foswiki::Infix::OP for details of the different options used | ||||
12 | to define operator nodes. | ||||
13 | |||||
14 | =cut | ||||
15 | |||||
16 | 2 | 44µs | 2 | 40µs | # spent 33µs (26+7) within Foswiki::Query::OP::BEGIN@16 which was called:
# once (26µs+7µs) by Foswiki::Query::OP_empty::BEGIN@14 at line 16 # spent 33µs making 1 call to Foswiki::Query::OP::BEGIN@16
# spent 7µs making 1 call to strict::import |
17 | 2 | 453µs | 2 | 50µs | # spent 33µs (16+17) within Foswiki::Query::OP::BEGIN@17 which was called:
# once (16µs+17µs) by Foswiki::Query::OP_empty::BEGIN@14 at line 17 # spent 33µs making 1 call to Foswiki::Query::OP::BEGIN@17
# spent 17µs making 1 call to warnings::import |
18 | |||||
19 | # Does not need to subclass, but is a subclass of... | ||||
20 | #use Foswiki::Infix::OP (); | ||||
21 | #our @ISA = ( 'Foswiki::Infix::OP' ); | ||||
22 | |||||
23 | # spent 1.35ms within Foswiki::Query::OP::new which was called 91 times, avg 15µs/call:
# 30 times (458µs+0s) by Foswiki::Query::UnaryOP::new at line 11 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/UnaryOP.pm, avg 15µs/call
# 27 times (435µs+0s) by Foswiki::Query::ConditionalOP::new at line 18 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/ConditionalOP.pm, avg 16µs/call
# 4 times (54µs+0s) by Foswiki::Query::OP_comma::new at line 22 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/OP_comma.pm, avg 14µs/call
# 3 times (45µs+0s) by Foswiki::Query::OP_and::new at line 23 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/OP_and.pm, avg 15µs/call
# 3 times (44µs+0s) by Foswiki::Query::OP_or::new at line 23 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/OP_or.pm, avg 15µs/call
# 3 times (43µs+0s) by Foswiki::Query::OP_div::new at line 19 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/OP_div.pm, avg 14µs/call
# 3 times (42µs+0s) by Foswiki::Query::OP_where::new at line 19 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/OP_where.pm, avg 14µs/call
# 3 times (39µs+0s) by Foswiki::Query::OP_plus::new at line 19 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/OP_plus.pm, avg 13µs/call
# 3 times (37µs+0s) by Foswiki::Query::OP_dot::new at line 19 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/OP_dot.pm, avg 12µs/call
# 3 times (36µs+0s) by Foswiki::Query::OP_minus::new at line 19 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/OP_minus.pm, avg 12µs/call
# 3 times (36µs+0s) by Foswiki::Query::OP_ref::new at line 21 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/OP_ref.pm, avg 12µs/call
# 3 times (36µs+0s) by Foswiki::Query::OP_times::new at line 19 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/OP_times.pm, avg 12µs/call
# once (18µs+0s) by Foswiki::Query::OP_empty::new at line 19 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/OP_empty.pm
# once (14µs+0s) by Foswiki::If::OP_ingroup::new at line 20 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/If/OP_ingroup.pm
# once (14µs+0s) by Foswiki::If::OP_allows::new at line 23 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/If/OP_allows.pm | ||||
24 | 91 | 358µs | my ( $class, %opts ) = @_; | ||
25 | 91 | 1.20ms | return bless( \%opts, $class ); | ||
26 | } | ||||
27 | |||||
28 | =begin TML | ||||
29 | |||||
30 | ---++ ObjectMethod evaluate($node, %domain) -> $value | ||||
31 | |||||
32 | Pure virtual method that evaluates the operator in the give domain. | ||||
33 | The domain is a reference to a hash that contains the | ||||
34 | data being operated on, and a reference to the meta-data of the topic being worked on | ||||
35 | (the "topic object"). The data being operated on can be a | ||||
36 | Meta object, a reference to an array (such as attachments), a reference | ||||
37 | to a hash or a scalar. Arrays can contain other arrays | ||||
38 | and hashes. | ||||
39 | |||||
40 | See Foswiki::Query::Node::evaluate for more information. | ||||
41 | |||||
42 | =cut | ||||
43 | |||||
44 | sub evaluate { | ||||
45 | my $this = shift; | ||||
46 | die "Operator '$this->{name}' does not define evaluate()"; | ||||
47 | } | ||||
48 | |||||
49 | =begin TML | ||||
50 | |||||
51 | ---++ ObjectMethod evaluatesToConstant() -> $boolean | ||||
52 | Does this operator always evaluate to a constant? | ||||
53 | See Foswiki::Query::Node::evaluatesToConstant | ||||
54 | |||||
55 | Used in hoisting/optimisation. | ||||
56 | |||||
57 | Default behaviour is to call evaluatesAsConstant on all | ||||
58 | parameters and return true if they all return true. | ||||
59 | |||||
60 | =cut | ||||
61 | |||||
62 | sub evaluatesToConstant { | ||||
63 | my $this = shift; | ||||
64 | my $node = shift; | ||||
65 | foreach my $i ( @{ $node->{params} } ) { | ||||
66 | return 0 unless $i->evaluatesToConstant(@_); | ||||
67 | } | ||||
68 | return 1; | ||||
69 | } | ||||
70 | |||||
71 | =begin TML | ||||
72 | |||||
73 | ---++ StaticMethod isNumber($string) -> $boolean | ||||
74 | |||||
75 | Determine if a string represents a valid number (signed decimal) | ||||
76 | |||||
77 | Used in hoisting/optimisation. | ||||
78 | |||||
79 | =cut | ||||
80 | |||||
81 | # spent 395µs (268+127) within Foswiki::Query::OP::isNumber which was called 24 times, avg 16µs/call:
# 22 times (246µs+104µs) by Foswiki::Query::ConditionalOP::compare at line 41 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/ConditionalOP.pm, avg 16µs/call
# 2 times (22µs+23µs) by Foswiki::Query::Node::_freeze at line 364 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/Node.pm, avg 23µs/call | ||||
82 | 24 | 388µs | 24 | 127µs | return shift =~ m/^[+-]?(\d+\.\d+|\d+\.|\.\d+|\d+)([eE][+-]?\d+)?$/; # spent 127µs making 24 calls to Foswiki::Query::OP::CORE:match, avg 5µs/call |
83 | } | ||||
84 | |||||
85 | =begin TML | ||||
86 | |||||
87 | ---++ StaticMethod collect($a, $fn) -> [] | ||||
88 | |||||
89 | Invokes $fn once for each element of $a and return an array built from the results. | ||||
90 | |||||
91 | =cut | ||||
92 | |||||
93 | sub collect { | ||||
94 | my ( $this, $a, $fn ) = @_; | ||||
95 | if ( ref($a) eq 'ARRAY' ) { | ||||
96 | my @b = map { $this->collect( $_, $fn ) } @$a; | ||||
97 | return \@b; | ||||
98 | } | ||||
99 | elsif ( ref($a) eq 'HASH' ) { | ||||
100 | die "Can't collect on a hash"; | ||||
101 | } | ||||
102 | else { | ||||
103 | return &$fn($a); | ||||
104 | } | ||||
105 | } | ||||
106 | |||||
107 | 1 | 4µs | 1; | ||
108 | __END__ | ||||
# spent 127µs within Foswiki::Query::OP::CORE:match which was called 24 times, avg 5µs/call:
# 24 times (127µs+0s) by Foswiki::Query::OP::isNumber at line 82, avg 5µs/call |