← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 18:42:36 2015
Reported on Fri Jul 31 18:48:14 2015

Filename/var/www/foswikidev/core/lib/Foswiki/Plugins/InterwikiPlugin.pm
StatementsExecuted 243 statements in 2.13ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111676µs10.7msFoswiki::Plugins::InterwikiPlugin::::initPluginFoswiki::Plugins::InterwikiPlugin::initPlugin
511497µs497µsFoswiki::Plugins::InterwikiPlugin::::preRenderingHandlerFoswiki::Plugins::InterwikiPlugin::preRenderingHandler
2711130µs130µsFoswiki::Plugins::InterwikiPlugin::::_mapFoswiki::Plugins::InterwikiPlugin::_map
11114µs26µsFoswiki::Plugins::InterwikiPlugin::::BEGIN@23Foswiki::Plugins::InterwikiPlugin::BEGIN@23
1119µs13µsFoswiki::Plugins::InterwikiPlugin::::BEGIN@24Foswiki::Plugins::InterwikiPlugin::BEGIN@24
1116µs6µsFoswiki::Plugins::InterwikiPlugin::::_trimWhitespaceFoswiki::Plugins::InterwikiPlugin::_trimWhitespace
1114µs4µsFoswiki::Plugins::InterwikiPlugin::::BEGIN@27Foswiki::Plugins::InterwikiPlugin::BEGIN@27
1114µs4µsFoswiki::Plugins::InterwikiPlugin::::BEGIN@40Foswiki::Plugins::InterwikiPlugin::BEGIN@40
1113µs3µsFoswiki::Plugins::InterwikiPlugin::::BEGIN@26Foswiki::Plugins::InterwikiPlugin::BEGIN@26
0000s0sFoswiki::Plugins::InterwikiPlugin::::_linkFoswiki::Plugins::InterwikiPlugin::_link
Call graph for these subroutines as a Graphviz dot language file.
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::Plugins::InterwikiPlugin
6
7Recognises and processes special links to other sites defined
8using "inter-site syntax".
9
10The recognized syntax is:
11<pre>
12 InterSiteName:TopicName
13</pre>
14
15Sites must start with upper case and must be preceded by white
16space, '-', '*' or '(', or be part of the link expression
17in a [[link]] or [[link][text]] expression.
18
19=cut
20
21package Foswiki::Plugins::InterwikiPlugin;
22
23227µs239µs
# spent 26µs (14+13) within Foswiki::Plugins::InterwikiPlugin::BEGIN@23 which was called: # once (14µs+13µs) by Foswiki::Plugin::BEGIN@2.20 at line 23
use strict;
# spent 26µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@23 # spent 13µs making 1 call to strict::import
24223µs217µs
# spent 13µs (9+4) within Foswiki::Plugins::InterwikiPlugin::BEGIN@24 which was called: # once (9µs+4µs) by Foswiki::Plugin::BEGIN@2.20 at line 24
use warnings;
# spent 13µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@24 # spent 4µs making 1 call to warnings::import
25
26219µs13µs
# spent 3µs within Foswiki::Plugins::InterwikiPlugin::BEGIN@26 which was called: # once (3µs+0s) by Foswiki::Plugin::BEGIN@2.20 at line 26
use Foswiki::Func (); # The plugins API
# spent 3µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@26
27289µs14µs
# spent 4µs within Foswiki::Plugins::InterwikiPlugin::BEGIN@27 which was called: # once (4µs+0s) by Foswiki::Plugin::BEGIN@2.20 at line 27
use Foswiki::Plugins (); # For the API version
# spent 4µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@27
28
291700nsour $VERSION = '1.22';
301100nsour $RELEASE = '1.22';
311100nsour $NO_PREFS_IN_TOPIC = 1;
321200nsour $SHORTDESCRIPTION =
33'Link !ExternalSite:Page text to external sites based on aliases defined in a rules topic';
34
351200nsmy $interLinkFormat;
361100nsmy $sitePattern;
371100nsmy $pagePattern;
381100nsmy %interSiteTable;
39
40
# spent 4µs within Foswiki::Plugins::InterwikiPlugin::BEGIN@40 which was called: # once (4µs+0s) by Foswiki::Plugin::BEGIN@2.20 at line 47
BEGIN {
41
42 # 'Use locale' for internationalisation of Perl sorting and searching -
4315µs if ( $Foswiki::cfg{UseLocale} ) {
44 require locale;
45 import locale();
46 }
471672µs14µs}
# spent 4µs making 1 call to Foswiki::Plugins::InterwikiPlugin::BEGIN@40
48
49# Read preferences and get all InterWiki Site->URL mappings
50
# spent 10.7ms (676µs+10.0) within Foswiki::Plugins::InterwikiPlugin::initPlugin which was called: # once (676µs+10.0ms) by Foswiki::Plugin::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Plugin.pm:257] at line 250 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm
sub initPlugin {
5112µs my ( $topic, $web, $user, $installWeb ) = @_;
52
53 # Regexes for the Site:page format InterWiki reference
5411µs %interSiteTable = ();
551600ns $sitePattern = "([[:upper:]][[:alnum:]]+)";
561800ns $pagePattern =
57 "((?:'[^']*')|(?:\"[^\"]*\")|(?:[[:alnum:]\_\~\%\/][[:alnum:]"
58 . '"\'\.\/\+\_\~\,\&\;\:\=\!\?\%\#\@\-\(\)]*?))';
59
60 # Get plugin preferences from InterwikiPlugin topic
6112µs123µs $interLinkFormat =
# spent 23µs making 1 call to Foswiki::Func::getPreferencesValue
62 Foswiki::Func::getPreferencesValue('INTERWIKIPLUGIN_INTERLINKFORMAT')
63 || '<a class="interwikiLink" href="$url" title="$tooltip"><noautolink>$label</noautolink></a>';
64
6513µs118µs my $rulesTopicPref =
# spent 18µs making 1 call to Foswiki::Func::getPreferencesValue
66 Foswiki::Func::getPreferencesValue('INTERWIKIPLUGIN_RULESTOPIC')
67 || 'InterWikis';
6813µs my @rulesTopics = split( ',', $rulesTopicPref );
6912µs foreach my $topic (@rulesTopics) {
7013µs16µs $topic = _trimWhitespace($topic);
71
7214µs112µs my ( $interWeb, $interTopic ) =
# spent 12µs making 1 call to Foswiki::Func::normalizeWebTopicName
73 Foswiki::Func::normalizeWebTopicName( $installWeb, $topic );
74
7513µs18.42ms if (
# spent 8.42ms making 1 call to Foswiki::Func::checkAccessPermission
76 !Foswiki::Func::checkAccessPermission(
77 'VIEW', $user, undef, $interTopic, $interWeb
78 )
79 )
80 {
81 Foswiki::Func::writeWarning(
82"InterwikiPlugin: user '$user' did not have permission to read the rules topic at '$interWeb.$interTopic'"
83 );
84 return 1;
85 }
8613µs1580µs my ( $meta, $text ) =
# spent 580µs making 1 call to Foswiki::Func::readTopic
87 Foswiki::Func::readTopic( $interWeb, $interTopic );
88
89 # '| alias | URL | ...' table and extract into 'alias', "URL" list
9028587µs29959µs $text =~ s/
# spent 829µs making 2 calls to utf8::SWASHNEW, avg 414µs/call # spent 130µs making 27 calls to Foswiki::Plugins::InterwikiPlugin::_map, avg 5µs/call
91 ^\|\s* # Start of table
92 $sitePattern
93 \s*\|\s* # Column separator
94 (.*?) # URL
95 \s*\|\s* # Column separator
96 (.*?) # tooltip
97 (?:
98 \s*\|\s* # Colunmn separator
99 ([^\|\n]+) # Not a separator or end of line
100 )?
101 \s*\|.*? # Last column separator
102 /_map($1,$2,$3,$4)/megx;
103
104 }
105
106110µs $sitePattern = "(" . join( "|", keys %interSiteTable ) . ")";
107
10815µs return 1;
109}
110
111
# spent 130µs within Foswiki::Plugins::InterwikiPlugin::_map which was called 27 times, avg 5µs/call: # 27 times (130µs+0s) by Foswiki::Plugins::InterwikiPlugin::initPlugin at line 90, avg 5µs/call
sub _map {
1122733µs my ( $site, $url, $tooltip, $format ) = @_;
113277µs if ($site) {
1142734µs $interSiteTable{$site}{url} = $url || '';
1152715µs $interSiteTable{$site}{tooltip} = $tooltip || '';
116276µs if ( defined $format ) {
11715µs $format =~ s/\s*$//g; # remove trailing spaces
1181900ns $interSiteTable{$site}{format} = $format;
119 }
120 }
1212762µs return '';
122}
123
124
# spent 497µs within Foswiki::Plugins::InterwikiPlugin::preRenderingHandler which was called 5 times, avg 99µs/call: # 5 times (497µs+0s) by Foswiki::Plugin::invoke at line 310 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm, avg 99µs/call
sub preRenderingHandler {
125
126 # ref in [[ref]] or [[ref][
127 $_[0] =~
1285198µss/(\[\[)$sitePattern:$pagePattern(\]\]|\]\[[^\]]+\]\])/_link($1,$2,$3,$4)/ge;
129
130 # ref in text
131 $_[0] =~
1325277µss/(^|[\s\-\*\=\_\(])$sitePattern:$pagePattern(?=[\s\.\,\;\:\!\?\)\*\=\_\|]*(\s|$))/_link($1,$2,$3)/ge;
133
134516µs return;
135}
136
137sub _link {
138 my ( $prefix, $site, $page, $postfix ) = @_;
139
140 $prefix ||= '';
141 $site ||= '';
142 $page ||= '';
143 $postfix ||= '';
144
145 my $upage = $page;
146 if ( $page =~ m/^['"](.*)["']$/ ) {
147 $page = $1;
148 $upage = Foswiki::urlEncode($1);
149 }
150
151 my $text = $prefix;
152 if ( defined( $interSiteTable{$site} ) ) {
153 my $tooltip = $interSiteTable{$site}{tooltip};
154 my $url = $interSiteTable{$site}{url};
155
156 #$url .= $page unless ( $url =~ m/\$page/ );
157
158 if ( $url =~ m/\$page/ ) {
159 $url =~ s/\$page/$upage/g;
160 }
161 else {
162 $url .= $upage;
163 }
164 my $label = '$site:$page';
165
166 if ($postfix) {
167
168 # [[...]] or [[...][...]] interwiki link
169 $text = '';
170 if ( $postfix =~ m/^\]\[([^\]]+)/ ) {
171 $label = $1;
172 }
173 }
174
175 my $format = $interSiteTable{$site}{format} || $interLinkFormat;
176 $format =~ s/\$url/$url/g;
177 $format =~ s/\$tooltip/$tooltip/g;
178 $format =~ s/\$label/$label/g;
179 $format =~ s/\$site/$site/g;
180 $format =~ s/\$page/$page/g;
181 $text .= $format;
182 }
183 else {
184 $text .= "$site\:$page$postfix";
185 }
186 $text = Foswiki::Func::expandCommonVariables($text);
187 return $text;
188}
189
190
# spent 6µs within Foswiki::Plugins::InterwikiPlugin::_trimWhitespace which was called: # once (6µs+0s) by Foswiki::Plugins::InterwikiPlugin::initPlugin at line 70
sub _trimWhitespace {
1911800ns my $string = shift;
19212µs $string =~ s/^\s+//;
19311µs $string =~ s/\s+$//;
19414µs return $string;
195}
196
19714µs1;
198__END__