Filename | /var/www/foswiki11/lib/Foswiki/Macros/QUERY.pm |
Statements | Executed 31 statements in 992µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 5.18ms | 5.70ms | BEGIN@72 | Foswiki::
1 | 1 | 1 | 78µs | 2.75ms | QUERY | Foswiki::
1 | 1 | 1 | 25µs | 42µs | BEGIN@4.79 | Foswiki::
1 | 1 | 1 | 22µs | 653µs | __ANON__[:56] | Foswiki::
1 | 1 | 1 | 15µs | 22µs | BEGIN@5.80 | Foswiki::
1 | 1 | 1 | 4µs | 4µs | _serialise_ | Foswiki::
1 | 1 | 1 | 3µs | 3µs | __ANON__[:65] | Foswiki::
0 | 0 | 0 | 0s | 0s | __ANON__[:62] | Foswiki::
0 | 0 | 0 | 0s | 0s | _serialise_json | Foswiki::
0 | 0 | 0 | 0s | 0s | _serialise_perl | Foswiki::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | package Foswiki; | ||||
3 | |||||
4 | 2 | 41µs | 2 | 59µs | # spent 42µs (25+17) within Foswiki::BEGIN@4.79 which was called:
# once (25µs+17µs) by Foswiki::_expandMacroOnTopicRendering at line 4 # spent 42µs making 1 call to Foswiki::BEGIN@4.79
# spent 17µs making 1 call to strict::import |
5 | 2 | 505µs | 2 | 29µs | # spent 22µs (15+7) within Foswiki::BEGIN@5.80 which was called:
# once (15µs+7µs) by Foswiki::_expandMacroOnTopicRendering at line 5 # spent 22µs making 1 call to Foswiki::BEGIN@5.80
# spent 7µs making 1 call to warnings::import |
6 | |||||
7 | 1 | 100ns | our $evalParser; # could share $ifParser from IF.pm | ||
8 | |||||
9 | # spent 2.75ms (78µs+2.68) within Foswiki::QUERY which was called:
# once (78µs+2.68ms) by Foswiki::_expandMacroOnTopicRendering at line 3160 of /var/www/foswiki11/lib/Foswiki.pm | ||||
10 | 1 | 900ns | my ( $this, $params, $topicObject ) = @_; | ||
11 | 1 | 100ns | my $result; | ||
12 | 1 | 700ns | my $expr = $params->{_DEFAULT}; | ||
13 | 1 | 200ns | $expr = '' unless defined $expr; | ||
14 | 1 | 1µs | my $style = lc( $params->{style} || '' ); | ||
15 | 1 | 400ns | my $rev = $params->{rev}; | ||
16 | |||||
17 | # FORMFIELD does its own caching. | ||||
18 | # Either the home-made cache there should go into Meta so that both | ||||
19 | # FORMFIELD and QUERY benefit, or the store should be made a lot smarter. | ||||
20 | |||||
21 | 1 | 10µs | 2 | 607µs | if ( defined $rev ) { # spent 590µs making 1 call to Foswiki::Meta::load
# spent 16µs making 1 call to Foswiki::Meta::latestIsLoaded |
22 | my $crev = $topicObject->getLoadedRev(); | ||||
23 | if ( defined $crev && $crev != $rev ) { | ||||
24 | $topicObject = | ||||
25 | Foswiki::Meta->load( $topicObject->session, $topicObject->web, | ||||
26 | $topicObject->topic, $rev ); | ||||
27 | } | ||||
28 | } | ||||
29 | elsif ( !$topicObject->latestIsLoaded() ) { | ||||
30 | |||||
31 | # load latest rev | ||||
32 | $topicObject = $topicObject->load(); | ||||
33 | } | ||||
34 | |||||
35 | # Recursion block. | ||||
36 | 1 | 2µs | $this->{evaluatingEval} ||= {}; | ||
37 | |||||
38 | # Block after 5 levels. | ||||
39 | 1 | 500ns | if ( $this->{evaluatingEval}->{$expr} | ||
40 | && $this->{evaluatingEval}->{$expr} > 5 ) | ||||
41 | { | ||||
42 | delete $this->{evaluatingEval}->{$expr}; | ||||
43 | return ''; | ||||
44 | } | ||||
45 | 1 | 500ns | unless ($evalParser) { | ||
46 | 1 | 1µs | require Foswiki::Query::Parser; | ||
47 | 1 | 11µs | 1 | 1.38ms | $evalParser = new Foswiki::Query::Parser(); # spent 1.38ms making 1 call to Foswiki::Query::Parser::new |
48 | } | ||||
49 | |||||
50 | 1 | 2µs | $this->{evaluatingEval}->{$expr}++; | ||
51 | # spent 653µs (22+631) within Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/QUERY.pm:56] which was called:
# once (22µs+631µs) by Error::subs::try at line 419 of Error.pm | ||||
52 | 1 | 5µs | 1 | 586µs | my $node = $evalParser->parse($expr); # spent 586µs making 1 call to Foswiki::Infix::Parser::parse |
53 | 1 | 5µs | 1 | 41µs | $result = $node->evaluate( tom => $topicObject, data => $topicObject ); # spent 41µs making 1 call to Foswiki::Query::Node::evaluate |
54 | 1 | 800ns | my $fn = "_serialise_$style"; | ||
55 | 1 | 8µs | 1 | 4µs | $result = $this->$fn($result); # spent 4µs making 1 call to Foswiki::_serialise_ |
56 | } | ||||
57 | catch Foswiki::Infix::Error with { | ||||
58 | my $e = shift; | ||||
59 | $result = | ||||
60 | $this->inlineAlert( 'alerts', 'generic', 'QUERY{', | ||||
61 | $params->stringify(), '}:', $e->{-text} ); | ||||
62 | } | ||||
63 | # spent 3µs within Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/QUERY.pm:65] which was called:
# once (3µs+0s) by Error::subs::try at line 433 of Error.pm | ||||
64 | 1 | 6µs | delete $this->{evaluatingEval}->{$expr}; | ||
65 | 1 | 26µs | 4 | 16µs | }; # spent 10µs making 1 call to Error::catch
# spent 4µs making 1 call to Error::subs::finally
# spent 2µs making 1 call to Error::subs::with
# spent 675µs making 1 call to Error::subs::try, recursion: max depth 1, sum of overlapping time 675µs |
66 | |||||
67 | 1 | 5µs | return $result; | ||
68 | } | ||||
69 | |||||
70 | sub _serialise_perl { | ||||
71 | my ( $this, $result ) = @_; | ||||
72 | 2 | 351µs | 1 | 5.70ms | # spent 5.70ms (5.18+517µs) within Foswiki::BEGIN@72 which was called:
# once (5.18ms+517µs) by Foswiki::_expandMacroOnTopicRendering at line 72 # spent 5.70ms making 1 call to Foswiki::BEGIN@72 |
73 | local $Data::Dumper::Indent = 0; | ||||
74 | local $Data::Dumper::Terse = 1; | ||||
75 | return Data::Dumper->Dump( [$result] ); | ||||
76 | } | ||||
77 | |||||
78 | sub _serialise_json { | ||||
79 | my ( $this, $result ) = @_; | ||||
80 | eval "require JSON"; | ||||
81 | if ($@) { | ||||
82 | return $this->inlineAlert( 'alerts', 'generic', | ||||
83 | 'Perl JSON module is not available' ); | ||||
84 | } | ||||
85 | return JSON::to_json( $result, { allow_nonref => 1 } ); | ||||
86 | } | ||||
87 | |||||
88 | # Default serialiser | ||||
89 | # spent 4µs within Foswiki::_serialise_ which was called:
# once (4µs+0s) by Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki/Macros/QUERY.pm:56] at line 55 | ||||
90 | 1 | 800ns | my ( $this, $result ) = @_; | ||
91 | 1 | 800ns | if ( ref($result) eq 'ARRAY' ) { | ||
92 | |||||
93 | # If any of the results is non-scalar, have to perl it | ||||
94 | foreach my $v (@$result) { | ||||
95 | if ( ref($v) ) { | ||||
96 | return _serialise_perl($result); | ||||
97 | } | ||||
98 | } | ||||
99 | return join( ',', @$result ); | ||||
100 | } | ||||
101 | elsif ( ref($result) ) { | ||||
102 | return _serialise_perl($result); | ||||
103 | } | ||||
104 | else { | ||||
105 | 1 | 6µs | return defined $result ? $result : ''; | ||
106 | } | ||||
107 | } | ||||
108 | |||||
109 | 1 | 3µs | 1; | ||
110 | __END__ |