MyFirstPlugin::Attrs;= instead of just =Package Attrs;=. Then call it using:
use TWiki::Plugins::MyFirstPlugin::Attrs;
$var = MyFirstPlugin::Attrs->new();
#MeasurePerformance
---+++ Measuring and Improving the Plugin Performance
A high quality Plugin performs well. You can use the TWiki:Plugins.PluginBenchmarkAddOn to measure your TWiki:Plugins.PluginBenchmarks. The data is needed as part of the Documentation Topic.
See also [[#FastPluginHints][Hints on Writing Fast Plugins]].
#CreatePluginTopic
---+++ Writing the Documentation Topic
The Plugin documentation topic contains usage instructions and version details. It serves the Plugin files as %TWIKIWEB%.FileAttachments for downloading. (The doc topic is also included _in_ the [[#CreatePluginPackage][distribution package]].) To create a documentation topic:
1. *Copy* the Plugin topic template from TWiki.org. To copy the text, go to TWiki:Plugins/PluginPackage and:
* enter the Plugin name in the "How to Create a Plugin" section
* click Create
* select all in the Edit box & copy
* Cancel the edit
* go back to your site to the %TWIKIWEB% web
* In the GoBox enter your Plugin name, for example =MyFirstPlugin=, press enter and create the new topic
* paste & save new Plugin topic on your site
1. *Customize* your Plugin topic.
* Important: In case you plan to publish your Plugin on TWiki.org, use Interwiki names for author names and links to TWiki.org topics, such as TWiki:Main/%WIKINAME%. This is important because links should work properly in a Plugin topic installed on any TWiki, not just on TWiki.org.
1. *Document* the performance data you gathered while [[#MeasurePerformance][measuring the performance]]
1. *Save* your topic, for use in [[#CreatePluginPackage][packaging]] and [[#PublishPlugin][publishing]] your Plugin.
*OUTLINE: Doc Topic Contents*
Check the Plugins web on TWiki.org for the latest Plugin doc topic template. Here's a quick overview of what's covered:
*Syntax Rules:* <Describe any special text formatting that will be rendered.>"
*Example:* <Include an example of the Plugin in action. Possibly include a static HTML version of the example to compare if the installation was a success!>"
*Plugin Settings:* <Description and settings for custom Plugin %VARIABLES%, and those required by TWiki.>"
* *Plugins Preferences* <If user settings are needed, explain... Entering values works exactly like %TWIKIWEB%.TWikiPreferences and WebPreferences: six (6) spaces and then:>"
* *Set <EXAMPLE = value added>*
*Plugin Installation Instructions:* <Step-by-step set-up guide, user help, whatever it takes to install and run, goes here.>"
*Plugin Info:* <Version, credits, history, requirements - entered in a form, displayed as a table. Both are automatically generated when you create or edit a page in the TWiki:Plugins web.>"
#CreatePluginPackage
---+++ Packaging for Distribution
The TWiki:Plugins.BuildContrib is a powerful build environment that is used by the TWiki project to build TWiki itself, as well as many of the Plugins. You don't *have* to use it, but it is highly recommended!
If you don't want (or can't) use the !BuildContrib, then a minimum Plugin release consists of a Perl module with a WikiName that ends in =Plugin=, ex: =MyFirstPlugin.pm=, and a documentation page with the same name(=MyFirstPlugin.txt=).
1. Distribute the Plugin files in a directory structure that mirrors TWiki. If your Plugin uses additional files, include them all:
* =lib/TWiki/Plugins/MyFirstPlugin.pm=
* =data/TWiki/MyFirstPlugin.txt=
* =pub/TWiki/MyFirstPlugin/uparrow.gif= [a required graphic]
2. Create a zip archive with the Plugin name (=MyFirstPlugin.zip=) and add the entire directory structure from Step 1. The archive should look like this:
* =lib/TWiki/Plugins/MyFirstPlugin.pm=
* =data/TWiki/MyFirstPlugin.txt=
* =pub/TWiki/MyFirstPlugin/uparrow.gif=
#PublishPlugin
---+++ Publishing for Public Use
You can release your tested, packaged Plugin to the TWiki community through the TWiki:Plugins web. All Plugins submitted to TWiki.org are available for download and further development in TWiki:Plugins/PluginPackage.
Publish your Plugin by following these steps:
1. *Post* the Plugin documentation topic in the TWiki:Plugins/PluginPackage:
* enter the Plugin name in the "How to Create a Plugin" section, for example =MyFirstPlugin=
* paste in the topic text from [[#CreatePluginTopic][Writing the Documentation Topic]] and save
1. *Attach* the distribution zip file to the topic, ex: =MyFirstPlugin.zip=
1. *Link* from the doc page to a new, blank page named after the Plugin, and ending in =Dev=, ex: =MyFirstPluginDev=. This is the discussion page for future development. (User support for Plugins is handled in TWiki:Support.)
1. *Put* the Plugin into the SVN repository, see TWiki:Plugins/ReadmeFirst (optional)
%N% Once you have done the above steps once, you can use the !BuildContrib to upload updates to your Plugin.
Thank you very much for sharing your Plugin with the TWiki community :-)
#RecommendedStorageOfPluginData
---++ Recommended Storage of Plugin Specific Data
Plugins sometimes need to store data. This can be Plugin internal data such as cache data, or data generated for browser consumption such as images. Plugins should store data using TWikiFuncDotPm functions that support saving and loading of topics and attachments.
---+++ Plugin Internal Data
You can create a Plugin "work area" using the =TWiki::Func::getWorkArea()= function, which gives you a persistant directory where you can store data files. By default they will not be web accessible. The directory is guaranteed to exist, and to be writable by the webserver user. For convenience, =TWiki::Func::storeFile()= and =TWiki::Func::readFile()= are provided to persistently store and retrieve simple data in this area.
---+++ Web Accessible Data
__Topic-specific data__ such as generated images can be stored in the topics attachment area, which is web accessible. Use the =TWiki::Func::saveAttachment()= function to store the data.
Recommendation for file name:
* Prefix the filename with an underscore (the leading underscore avoids a nameclash with files attached to the same topic)
* Identify where the attachment originated from, typically by including the Plugin name in the file name
* Use only alphanumeric characters, underscores, dashes and periods to avoid platform dependency issues and URL issues
* Example: =_FooBarPlugin_img123.gif=
__Web specific data__ can be stored in the Plugin's attachment area, which is web accessible. Use the =TWiki::Func::saveAttachment()= function to store the data.
Recommendation for file names in Plugin attachment area:
* Prefix the filename with an underscore
* Include the name of the web in the filename
* Use only alphanumeric characters, underscores, dashes and periods to avoid platform dependency issues and URL issues
* Example: =_Main_roundedge-ul.gif=
#MaintainPlugins
---++ Maintaining Plugins
---+++ Discussions and Feedback on Plugins
Each published Plugin has a Plugin development topic on TWiki.org. Plugin development topics are named after your Plugin and end in =Dev=, such as =MyFirstPluginDev=. The Plugin development topic is a great resource to discuss feature enhancements and to get feedback from the TWiki community.
---+++ Maintaining Compatibility with Earlier TWiki Versions
The Plugin interface (TWikiFuncDotPm functions and handlers) evolve over time. TWiki 4.0 introduced new API functions to address the needs of Plugin authors. It also deprecated some functions. Some Plugins written for earlier TWiki releases using unofficial TWiki internal functions no longer work on the TWiki 4.0 codebase. All this means that some Plugins need to be updated to work on the TWiki 4.0 codebase.
Organizations typically do not upgrade to the latest TWiki for many months. However, many administrators still would like to install the latest versions of a Plugin on their older TWiki installation. This need is fullfilled if Plugins are maintained in a compatible manner.
__%T% Tip:__ Plugins can be written to be compatible with older and newer TWiki releases. This can be done also for Plugins using unofficial TWiki internal functions of an earlier release that no longer work on the latest TWiki codebase. TWiki:TWiki.TWikiPluginsSupplement#MaintainPlugins has more.
---+++ Handling deprecated functions
From time-to-time, the TWiki developers will add new functions to the interface (either to TWikiFuncDotPm, or new handlers). Sometimes these improvements mean that old functions have to be deprecated to keep the code manageable. When this happens, the deprecated functions will be supported in the interface for at least one more TWiki release, and probably longer, though this cannot be guaranteed.
When a plugin defines deprecated handlers, a warning will be shown in the list generated by %FAILEDPLUGINS%. Admins who see these warnings should check TWiki.org and if necessary, contact the plugin author, for an updated version of the plugin.
Updated plugins may still need to define deprecated handlers for compatibility with old TWiki versions. In this case, the plugin package that defines old handlers can suppress the warnings in %FAILEDPLUGINS%.
This is done by defining a map from the handler name to the =TWiki::Plugins= version _in which the handler was first deprecated_. For example, if we need to define the =endRenderingHandler= for compatibility with =TWiki::Plugins= versions before 1.1, we would add this to the plugin:
package TWiki::Plugins::SinkPlugin;
use vars qw( %TWikiCompatibility );
$TWikiCompatibility{endRenderingHandler} = 1.1;
If the currently-running TWiki version is 1.1 _or later_, then the _handler will not be called_ and _the warning will not be issued_. TWiki with versions of =TWiki::Plugins= before 1.1 will still call the handler as required.
%STOPINCLUDE%
__Related Topics:__ DeveloperDocumentationCategory, AdminDocumentationCategory, TWiki:TWiki.TWikiPluginsSupplement
-- __Contributors:__ TWiki:Main.PeterThoeny, TWiki:Main.AndreaSterbini, TWiki:MainMikeMannix, TWiki:CrawfordCurrie