What Is A Mod File |
APF Modification File SystemIn this document I will attempt to explain the external modification system that MrRat, the developer of the Amazon Products Feed perl script, has integrated into APF since the release of Version 4. Background to this document:I have been programming with PERL for maybe 6-8 weeks, so when OneClick showed me the code snippet that appears below by way of an introduction to the system of modification files or Mod files that MrRat is implementing in APF4, I was stopped dead in my tracks. I set about analysing the code line by line in order to pose more questions. By the time I had a handle on what the code was doing, I was sure that many others would have questions to ask. This document is intended to introduce the Mod file system to people who can already program in PERL. You do not need to be an 'advanced' level programmer like MrRat, but if you have hacked around in other people's PERL scripts in the past, then this document should be enough to get you started. If you still have questions at the end, post them in the Mods forum at this address: http://www.absolutefreebies.com/phpBB2/ we will do our best to answer them, and if necessary alter / modify this document to clarify any issues arising. Below we will look at the following questions:
What are mod files and why would you want to build / use a mod?A mod file or modification file is a piece of code that alters the way that MrRat's APF script works.
Possible implementations:
Because a mod file is a piece of script it can evaluate options and produce output based on an: If ... then ... else ... structure. Think of the possibilities - if I can grab this variable I can have different output conditional upon the value of xyz. Just think of the possibilities:
Another benefit of the mod file system - externalise your editsPreviously if you wanted to edit the output of the APF script you would 'hack' the script with your custom code - but if you changed to a new version you lost your edits or you had to spend hours (or days) combing through the old code to identify your edits ready for copying them across to the new version. Hacking the script created an obvious impedement to upgrading. Implementing edits via mod files overcame this impediment. You simply install your mod file into the new version of the script and activate it in the config screen and it continues to work - usually. The process of upgrading from one version of the script to another where modifications have been made. With previous versions people would invest a lot of time and energy editing the main script file with their own modifications. Then when the next bug fix or upgrade was released they would have to replicate all of those changes in the new script. The modification file system externalises this process - making modifications modular. The core script can be upgraded as many times as is necessary without losing any modifications - or sleep. So how do mod files work?As each of the subs within MrRat's APF script executes, it checks whether any of the loaded mod files want to hook into the process at that point. Any correctly constructed Mod file can hook into any number of subs as long as the subs themselves are enabled. Warning Technobable aheadFor the more technically minded here is the science (code actually):Many areas of MrRat's code contain this piece of code Let me try and walk you through what is going on here
Which parts of MrRat's script can we hook into.Main Control Structure of MrRat's Script.get_url_input(); # Yes - if there is a query string.initialize_locale(); # Yesload_language(); # Yesinitialize_hashes(); # YesSTART_PROCESSING_LABEL:calculate_initial_variables(); # Yesbuild_products(); # Nobuild_the_page__main(); # Yes - just before HTML is printed. # but too late for automatic inclusion of changed or new $MY_variables. Variables available to mod file builders:
%MY_variables - the main data structure for template variables and script output
%store_to_browse -
%$level_1; @mod_files; @months; %MY_variable TYPE: hash or associative array I didn't understand any of that - can you explain some PERL to me?There is not room here for a full tutorial on PERL programming. If you know what a hash or associative array is then you are good to go. If not, then try these resources for more in-depth information on PERL programming. A fairly complete list of Perl functions and keywords The Perl Cookbook - code snippets that complete specified tasks, together with some useful commentary. Type perl tutorial into your favourite search engine. APF Related linksIf you want to see an example of a Mod file click here. See the central repository for Mod and Template files - APFMods.com . |
|||||||||||