Tags:
create new tag
view all tags

Question

I had hoped, after Martin's very helpful comments that my issues with getting a first plugin working were over with but I'm obviously still missing some key step.

Ignore that the code in the plugin is ridiculously simple because I'm after simple proof that I understand the process before moving on to writing top code (well I can dream).

Have read much documentation and whatever support questions I could find that shed light as well as asking previous questions and am more than certain that I understand what is happening as TWiki dynamically builds up web pages from TWiki variables. I have also, since February acheived reasonable proficiency in reading perldocs (and even in working out which perldoc to look in for x).

In most cases the TWiki variable is worked out by binding $_[0] to a substitution (s///) with the example line out of EmptyPlugin.pm

e.g.

$_[0] =~ s/%TWikivariable%/$builtup variable/geom;

or

$_[0] =~ s/%TWikivariable%/&_somesubroutine/geom;

I basically found Peter's response in HowToExecuteAScript to be more enlightening than half the documents I read (pithy examples I can cognate are a godsend). This prompted me to take a simple task and see if I understood the variable substitution process by replacing a TWiki variable (%TableFolderListing%) with a HTML table containing a display of folder contents with each file in it's own cell (I said that it was stupidly trivial code). MartinCleaver pointed out in my earlier question MyFirstPluginErrors that I had some syntax errors and that I missed a 1: at the end of my subroutine - he also pointed out the usefulness of the perl -c switch (been using it all week Martin, thanks again) and other than that his reaction to the plugin indicated that I understood the structure - excellent.

Not. Sadly I'm obviously one of the expletive deleted's on the planet as I can't get %TableFolderListing% to be translated into a table.

Steps I've taken so far:

1) Written the subroutine as a perlscript and got it working.

2) Got subroutine to run (thanks MC)

3) Written a seperate plugin (with accompanying txt file) that has following line in handleCommonTags $_[0] =~ s/%TableFolderListin%/&TableFolderListing/gm; to call and assign the results of the sub to the variable - didn't work.

4) Added the code as a sub (with the same line above) to the DefaultPlugin in case I'd stuffed up the plugin creation - no joy.

5) Back to basics, sod the subroutine, simply assign text to $variable and bind that variable to %TWikiVariable%. Still no joy.

Am left with wondering whether I've understood how the dynamic substitution takes place.

One thing to note is that the variable $TableFolderListing is in the following format
|filename|codename|version|
|filename2|codename2|version|

This is itself a form of TWiki shorthand and what I'm left wondering is could this be the cause i.e. using TWiki variables to output TWiki shorthand which itself has to be recursively parsed - I thought it was inefficient but didn't care in this case as it was only to confirm my own proof of understanding (I would actually build the table up using HTML tags if I was to write the full plugin).

Now that I'm becoming more familiar with them I like the writeDebug modules and I like the Plugins diagnostic page but, and this is the irritating bit, my code doesn't produce errors for warning.txt and debug.txt shows that the %TableFolderListing% is not having the variable $TableFolderListing from the sub bound to it.

Environment

TWiki version: TWikiRelease02Sep2004
TWiki plugins:   DefaultPlugin, SpreadSheetPlugin, ApprovalPlugin, CommentPlugin, EditTablePlugin, InterwikiPlugin, RenderListPlugin, SlideShowPlugin, SmiliesPlugin, TablePlugin
Server OS: Win XP Pro
Web server: Apache 1.3.33
Perl version: Perl 5.8.6 (Cygwin)
Client OS: various
Web Browser: IE 6, Firefox
Categories: Plugins

-- SteveMayes - 13 Apr 2005

Answer

Another handy hint is to ensure your plugin has a

use strict;

at the top.

The pathologically simplest example is:

sub commonTagsHandler;
{
    $_[0] =~ s/%MYVAR%/Var substituted/;
}

If properly initialized (it should list in TWiki.InstalledPlugins) the plugin will replace instances of %MYVAR% with the string "Var substituted".

Steve, it would be useful if you start gather all the snippets you find useful into a new topic so we can build a tutorial for the next user.

-- MartinCleaver - 13 Apr 2005

Yep, that ties in with my understanding of the substitution. And as well as use strict, I also use warnings and use diagnostics.

The painful path is already being documented Martin, if only for my own amusement later on. I had to remove Plugin.NiceFolderDisplayPlugin from my list of successfully installed plugins for the Environment section above - that is to say, it shows up as successfully installed but doesn't expand the variable.

-- SteveMayes - 14 Apr 2005

Update on TWiki.InstalledPlugins: Plugin.NiceFolderDisplayPlugin does indeed show up in 'Plugins defined' but when I look down to the table immediately below that there is an anomaly. (I'm assuming that this lower table shows which plugins have fired up which subroutines) Although Plugin.NiceFolderDisplayPlugin shows up in the row 'initPlugin' it doesn't show up in the commonTagsHandler row, excuse me whilst I delve further.

-- SteveMayes - 14 Apr 2005

Not suprising, if that semicolon on the end of the sub commonTagsHandler line is still there.

-- CrawfordCurrie - 14 Apr 2005

Dry, witty, pithy. You're either Canadian or British Crawford. ;-)

You're also correct. Damn.

-- SteveMayes - 14 Apr 2005

Whoops, sorry, I forgot to attach one of these:
hazard.gif
wink

-- CrawfordCurrie - 17 Apr 2005

Topic attachments
I Attachment History Action Size Date Who Comment
Perl source code filepm FolderDisplayPlugin.pm r1 manage 3.1 K 2005-04-13 - 15:52 UnknownUser  
GIFgif hazard.gif r1 manage 7.6 K 2005-04-17 - 15:40 UnknownUser  
Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2005-06-06 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.