Filename | /var/www/foswiki11/lib/Foswiki/Infix/Node.pm |
Statements | Executed 1764 statements in 2.96ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
246 | 2 | 2 | 1.32ms | 1.32ms | newNode | Foswiki::Infix::Node::
140 | 2 | 1 | 732µs | 1.58ms | newLeaf | Foswiki::Infix::Node::
1 | 1 | 1 | 24µs | 46µs | BEGIN@14 | Foswiki::Infix::Node::
1 | 1 | 1 | 16µs | 25µs | BEGIN@15 | Foswiki::Infix::Node::
0 | 0 | 0 | 0s | 0s | MONITOR_EVAL | Foswiki::Infix::Node::
0 | 0 | 0 | 0s | 0s | evaluate | Foswiki::Infix::Node::
0 | 0 | 0 | 0s | 0s | stringify | Foswiki::Infix::Node::
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::Infix::Node | ||||
6 | |||||
7 | Base class for node types generated by Infix::Parser. You don't *have* to use | ||||
8 | it, but it may be useful. | ||||
9 | |||||
10 | =cut | ||||
11 | |||||
12 | package Foswiki::Infix::Node; | ||||
13 | |||||
14 | 2 | 50µs | 2 | 68µs | # spent 46µs (24+22) within Foswiki::Infix::Node::BEGIN@14 which was called:
# once (24µs+22µs) by Foswiki::Infix::Parser::BEGIN@21 at line 14 # spent 46µs making 1 call to Foswiki::Infix::Node::BEGIN@14
# spent 22µs making 1 call to strict::import |
15 | 2 | 652µs | 2 | 34µs | # spent 25µs (16+9) within Foswiki::Infix::Node::BEGIN@15 which was called:
# once (16µs+9µs) by Foswiki::Infix::Parser::BEGIN@21 at line 15 # spent 25µs making 1 call to Foswiki::Infix::Node::BEGIN@15
# spent 9µs making 1 call to warnings::import |
16 | |||||
17 | # 1 for debug | ||||
18 | sub MONITOR_EVAL { 0 } | ||||
19 | |||||
20 | # Leaf token types | ||||
21 | 1 | 700ns | our $NAME = 1; | ||
22 | 1 | 200ns | our $NUMBER = 2; | ||
23 | 1 | 200ns | our $STRING = 3; | ||
24 | |||||
25 | =begin TML | ||||
26 | |||||
27 | ---++ ClassMethod newNode( $o, @p ) -> \$if | ||||
28 | |||||
29 | Construct a new parse node (contract with Infix::Parser) | ||||
30 | |||||
31 | =cut | ||||
32 | |||||
33 | # spent 1.32ms within Foswiki::Infix::Node::newNode which was called 246 times, avg 5µs/call:
# 140 times (848µs+0s) by Foswiki::Infix::Node::newLeaf at line 52, avg 6µs/call
# 106 times (468µs+0s) by Foswiki::Infix::Parser::_apply at line 319 of /var/www/foswiki11/lib/Foswiki/Infix/Parser.pm, avg 4µs/call | ||||
34 | 246 | 83µs | my $class = shift; | ||
35 | 246 | 64µs | my $op = shift; | ||
36 | 246 | 290µs | my $this = bless( {}, $class ); | ||
37 | 246 | 412µs | @{ $this->{params} } = @_; | ||
38 | 246 | 139µs | $this->{op} = $op; | ||
39 | 246 | 681µs | return $this; | ||
40 | } | ||||
41 | |||||
42 | =begin TML | ||||
43 | |||||
44 | ---++ ClassMethod newLeaf( $val, $type ) -> \$if | ||||
45 | |||||
46 | Construct a new terminal node (contract with Infix::Parser) | ||||
47 | |||||
48 | =cut | ||||
49 | |||||
50 | # spent 1.58ms (732µs+848µs) within Foswiki::Infix::Node::newLeaf which was called 140 times, avg 11µs/call:
# 139 times (722µs+838µs) by Foswiki::Query::Node::newLeaf at line 91 of /var/www/foswiki11/lib/Foswiki/Query/Node.pm, avg 11µs/call
# once (10µs+10µs) by Foswiki::Query::Node::newLeaf at line 88 of /var/www/foswiki11/lib/Foswiki/Query/Node.pm | ||||
51 | 140 | 113µs | my ( $class, $val, $type ) = @_; | ||
52 | 140 | 473µs | 140 | 848µs | return newNode( $class, $type, $val ); # spent 848µs making 140 calls to Foswiki::Infix::Node::newNode, avg 6µs/call |
53 | } | ||||
54 | |||||
55 | =begin TML | ||||
56 | |||||
57 | ---++ ObjectMethod evaluate(...) -> $result | ||||
58 | |||||
59 | Execute the parse node. The parameter array is passed on, by reference, | ||||
60 | to the evaluation functions. | ||||
61 | |||||
62 | =cut | ||||
63 | |||||
64 | sub evaluate { | ||||
65 | my ( $this, $clientData ) = @_; | ||||
66 | |||||
67 | my $result; | ||||
68 | if ( !ref( $this->{op} ) ) { | ||||
69 | $result = $this->{params}[0]; | ||||
70 | if (MONITOR_EVAL) { | ||||
71 | print STDERR "LEAF: ", ( defined($result) ? $result : 'undef' ), | ||||
72 | "\n"; | ||||
73 | } | ||||
74 | } | ||||
75 | else { | ||||
76 | my $fn = $this->{op}->{evaluate}; | ||||
77 | $result = &$fn( $clientData, @{ $this->{params} } ); | ||||
78 | if (MONITOR_EVAL) { | ||||
79 | print STDERR "NODE: ", $this->stringify(), " -> ", | ||||
80 | ( defined($result) ? $result : 'undef' ), "\n"; | ||||
81 | } | ||||
82 | } | ||||
83 | return $result; | ||||
84 | } | ||||
85 | |||||
86 | sub stringify { | ||||
87 | my $this = shift; | ||||
88 | |||||
89 | unless ( ref( $this->{op} ) ) { | ||||
90 | if ( $this->{op} == $Foswiki::Infix::Node::STRING ) { | ||||
91 | return "'$this->{params}[0]'"; | ||||
92 | } | ||||
93 | else { | ||||
94 | return $this->{params}[0]; | ||||
95 | } | ||||
96 | } | ||||
97 | |||||
98 | return | ||||
99 | $this->{op}->{name} . '{' | ||||
100 | . join( ',', map { $_->stringify() } @{ $this->{params} } ) . '}'; | ||||
101 | } | ||||
102 | |||||
103 | 1 | 6µs | 1; | ||
104 | __END__ |