← 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/ExtendedWebListPlugin.pm
StatementsExecuted 209 statements in 1.00ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111363µs38.3msFoswiki::Plugins::ExtendedWebListPlugin::::_EXTENDEDWEBLISTFoswiki::Plugins::ExtendedWebListPlugin::_EXTENDEDWEBLIST
11117µs31µsFoswiki::Plugins::ExtendedWebListPlugin::::BEGIN@33Foswiki::Plugins::ExtendedWebListPlugin::BEGIN@33
11117µs42µsFoswiki::Plugins::ExtendedWebListPlugin::::initPluginFoswiki::Plugins::ExtendedWebListPlugin::initPlugin
11110µs57µsFoswiki::Plugins::ExtendedWebListPlugin::::BEGIN@37Foswiki::Plugins::ExtendedWebListPlugin::BEGIN@37
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
2#
3# Copyright (C) 2008 Kenneth Lavrsen, kenneth@lavrsen.dk
4#
5# This program is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License
7# as published by the Free Software Foundation; either version 2
8# of the License, or (at your option) any later version. For
9# more details read LICENSE in the root of this distribution.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14#
15# For licensing info read LICENSE file in the Foswiki root.
16#<<<
17
18=pod
19
20---+ package ExtendedWebListPlugin
21
22__NOTE:__ When writing handlers, keep in mind that these may be invoked
23on included topics. For example, if a plugin generates links to the current
24topic, these need to be generated before the afterCommonTagsHandler is run,
25as at that point in the rendering loop we have lost the information that we
26the text had been included from another topic.
27
28=cut
29
30package Foswiki::Plugins::ExtendedWebListPlugin;
31
32# Always use strict to enforce variable scoping
33238µs245µs
# spent 31µs (17+14) within Foswiki::Plugins::ExtendedWebListPlugin::BEGIN@33 which was called: # once (17µs+14µs) by Foswiki::Plugin::BEGIN@2.15 at line 33
use strict;
# spent 31µs making 1 call to Foswiki::Plugins::ExtendedWebListPlugin::BEGIN@33 # spent 14µs making 1 call to strict::import
34
35# $VERSION is referred to by Foswiki, and is the only global variable that
36# *must* exist in this package.
3716µs146µs
# spent 57µs (10+46) within Foswiki::Plugins::ExtendedWebListPlugin::BEGIN@37 which was called: # once (10µs+46µs) by Foswiki::Plugin::BEGIN@2.15 at line 39
use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION $debug
# spent 46µs making 1 call to vars::import
38 $pluginName $NO_PREFS_IN_TOPIC
391591µs157µs );
# spent 57µs making 1 call to Foswiki::Plugins::ExtendedWebListPlugin::BEGIN@37
40
41# This should always be $Rev: 1243 (10 Dec 2008) $ so that TWiki can determine the checked-in
42# status of the plugin. It is used by the build automation tools, so
43# you should leave it alone.
441600ns$VERSION = '1.1';
45
46# This is a free-form string you can use to "name" your own plugin version.
47# It is *not* used by the build automation tools, but is reported as part
48# of the version number in PLUGINDESCRIPTIONS.
491200ns$RELEASE = '1.1';
50
51# Short description of this plugin
52# One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic:
531500ns$SHORTDESCRIPTION = 'Extended Web List Plugin provides the ability to only show subwebs within current top web.';
54
55# You must set $NO_PREFS_IN_TOPIC to 0 if you want your plugin to use preferences
56# stored in the plugin topic. This default is required for compatibility with
57# older plugins, but imposes a significant performance penalty, and
58# is not recommended. Instead, use $Foswiki::cfg entries set in LocalSite.cfg, or
59# if you want the users to be able to change settings, then use standard TWiki
60# preferences that can be defined in your %USERSWEB%.SitePreferences and overridden
61# at the web and topic level.
621200ns$NO_PREFS_IN_TOPIC = 0;
63
64# Name of this Plugin, only used in this module
651200ns$pluginName = 'ExtendedWebListPlugin';
66
67=pod
68
69---++ initPlugin($topic, $web, $user, $installWeb) -> $boolean
70 * =$topic= - the name of the topic in the current CGI query
71 * =$web= - the name of the web in the current CGI query
72 * =$user= - the login name of the user
73 * =$installWeb= - the name of the web the plugin is installed in
74
75REQUIRED
76
77Called to initialise the plugin. If everything is OK, should return
78a non-zero value. On non-fatal failure, should write a message
79using Foswiki::Func::writeWarning and return 0. In this case
80%FAILEDPLUGINS% will indicate which plugins failed.
81
82In the case of a catastrophic failure that will prevent the whole
83installation from working safely, this handler may use 'die', which
84will be trapped and reported in the browser.
85
86You may also call =Foswiki::Func::registerTagHandler= here to register
87a function to handle variables that have standard TWiki syntax - for example,
88=%MYTAG{"my param" myarg="My Arg"}%. You can also override internal
89TWiki variable handling functions this way, though this practice is unsupported
90and highly dangerous!
91
92__Note:__ Please align variables names with the Plugin name, e.g. if
93your Plugin is called FooBarPlugin, name variables FOOBAR and/or
94FOOBARSOMETHING. This avoids namespace issues.
95
96
97=cut
98
99
# spent 42µs (17+25) within Foswiki::Plugins::ExtendedWebListPlugin::initPlugin which was called: # once (17µs+25µs) 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 {
10012µs my( $topic, $web, $user, $installWeb ) = @_;
101
102 # check for Plugins.pm versions
103113µs18µs if( $Foswiki::Plugins::VERSION < 1.026 ) {
# spent 8µs making 1 call to version::vxs::VCMP
104 Foswiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" );
105 return 0;
106 }
107
108 # Set plugin preferences in LocalSite.cfg
10912µs $debug = $Foswiki::cfg{Plugins}{ExtendedWebListPlugin}{Debug} || 0;
110
11112µs117µs Foswiki::Func::registerTagHandler( 'EXTENDEDWEBLIST', \&_EXTENDEDWEBLIST );
# spent 17µs making 1 call to Foswiki::Func::registerTagHandler
112
113 # Plugin correctly initialized
11414µs return 1;
115}
116
117
# spent 38.3ms (363µs+37.9) within Foswiki::Plugins::ExtendedWebListPlugin::_EXTENDEDWEBLIST which was called: # once (363µs+37.9ms) by Foswiki::Func::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Func.pm:662] at line 660 of /var/www/foswikidev/core/lib/Foswiki/Func.pm
sub _EXTENDEDWEBLIST {
11811µs my($session, $params, $theTopic, $theWeb) = @_;
119 # $session - a reference to the TWiki session object (if you don't know
120 # what this is, just ignore it)
121 # $params= - a reference to a Foswiki::Attrs object containing parameters.
122 # This can be used as a simple hash that maps parameter names
123 # to values, with _DEFAULT being the name for the default
124 # parameter.
125 # $theTopic - name of the topic in the query
126 # $theWeb - name of the web in the query
127 # Return: the result of processing the variable
128
129 # For example, %EXAMPLETAG{'hamburger' sideorder="onions"}%
130 # $params->{_DEFAULT} will be 'hamburger'
131 # $params->{sideorder} will be 'onions'
132
13312µs my $format = $params->{_DEFAULT} || $params->{'format'} || '$name';
1341500ns $format ||= '$name';
1351800ns my $separator = $params->{separator} || "\n";
1361600ns $separator =~ s/\$n/\n/;
1371700ns my $web = $params->{web} || '';
1381500ns my $webs = $params->{webs} || 'public';
1391400ns my $rootwebs = $params->{rootwebs} || 'on';
1401800ns my $selection = $params->{selection} || '';
1411500ns my $showWeb = $params->{subwebs} || '';
1421300ns $selection =~ s/\,/ /g;
1431900ns $selection = " $selection ";
1441400ns my $marker = $params->{marker} || 'selected="selected"';
1451200ns $web =~ s#\.#/#go;
146
1471900ns my @list = ();
14813µs my @webslist = split( /,\s*/, $webs );
149
15012µs foreach my $aweb ( @webslist ) {
15111µs if ( $aweb eq 'public' ) {
1521400ns if ( $rootwebs eq 'on' ) {
1531700ns my @sublist = ();
1541400ns my @templist = ();
15515µs my @currentRootWeb = split(/\//, $showWeb);
15616µs131.4ms push( @templist, Foswiki::Func::getListOfWebs( 'user,public,allowed', '' ) );
# spent 31.4ms making 1 call to Foswiki::Func::getListOfWebs
15713µs16.41ms push( @sublist, Foswiki::Func::getListOfWebs( 'user,public,allowed', $currentRootWeb[0] ) );
# spent 6.41ms making 1 call to Foswiki::Func::getListOfWebs
158
15913µs foreach my $listitem ( @templist ) {
1601716µs if ( $listitem !~ /\// ) {
16183µs push( @list, $listitem );
162847µs if ( $showWeb =~ /\b$listitem\b/ ) {
163 push ( @list, @sublist );
164 }
165 }
166 }
167
168 }
169 else {
170 push( @list, Foswiki::Func::getListOfWebs( 'user,public,allowed', $showWeb ) );
171 }
172 }
173 elsif ( $aweb eq 'webtemplate' ) {
174 push( @list, Foswiki::Func::getListOfWebs( 'template,allowed', $showWeb ) );
175 }
176 else {
177 push( @list, $aweb ) if ( Foswiki::Func::webExists( $aweb ) );
178 }
179 }
180
1811200ns my @items;
18217µs169µs my $indent = CGI::span( { class => 'foswikiWebIndent' }, '' );
# spent 69µs making 1 call to CGI::span
18311µs foreach my $item ( @list ) {
184123µs my $line = $format;
1851212µs $line =~ s/\$web\b/$web/g;
1861234µs $line =~ s/\$name\b/$item/g;
1871233µs $line =~ s/\$qname/"$item"/g;
188122µs my $indenteditem = $item;
189125µs $indenteditem =~ s#/$##g;
1901212µs $indenteditem =~ s#\w+/#$indent#g;
1911221µs $line =~ s/\$indentedname/$indenteditem/g;
1921257µs my $mark = ( $selection =~ / \Q$item\E / ) ? $marker : '';
1931231µs $line =~ s/\$marker/$mark/g;
1941210µs push( @items, $line );
195 }
196112µs return join( $separator, @items );
197}
198
199#>>>
200
20114µs1;