From: <de...@de...> - 2011-02-12 21:27:14
|
Author: PeterThoeny Date: 2011-02-12 15:27:07 -0600 (Sat, 12 Feb 2011) New Revision: 20428 Trac url: http://develop.twiki.org/trac/changeset/20428 Added: twiki/branches/TWikiRelease05x00/QRCodePlugin/lib/TWiki/Plugins/QRCodePlugin/Core.pm Modified: twiki/branches/TWikiRelease05x00/QRCodePlugin/data/TWiki/QRCodePlugin.txt twiki/branches/TWikiRelease05x00/QRCodePlugin/lib/TWiki/Plugins/QRCodePlugin.pm twiki/branches/TWikiRelease05x00/QRCodePlugin/lib/TWiki/Plugins/QRCodePlugin/MANIFEST Log: Item6647: Lazy loading of core and CPAN modules for better performance when QRCODE is not used Modified: twiki/branches/TWikiRelease05x00/QRCodePlugin/data/TWiki/QRCodePlugin.txt =================================================================== --- twiki/branches/TWikiRelease05x00/QRCodePlugin/data/TWiki/QRCodePlugin.txt 2011-02-12 21:25:26 UTC (rev 20427) +++ twiki/branches/TWikiRelease05x00/QRCodePlugin/data/TWiki/QRCodePlugin.txt 2011-02-12 21:27:07 UTC (rev 20428) @@ -1,4 +1,4 @@ -%META:TOPICINFO{author="TWikiContributor" date="1297494969" format="1.1" version="$Rev$"}% +%META:TOPICINFO{author="TWikiContributor" date="1297545801" format="1.1" version="$Rev$"}% ---+!! !QRCodePlugin <!-- Contributions to this plugin are appreciated. Please update the plugin page at @@ -99,7 +99,7 @@ ---++ Examples ----+++!! Example: Small QR Code for =http://twiki.org/= +---+++ Small QR Code for URL!! =http://twiki.org/= <table border="0" cellpadding="10" cellspacing="2"> <tr bgcolor="#dddddd"> @@ -125,7 +125,7 @@ <img src="%ATTACHURLPATH%/qrcode-example-1.png" alt="qrcode-example-1.png" width="99" height="99" /> </td></tr></table> ----+++!! Example: Encode URL of current topic +---+++ Encode URL of current topic The QR Code of the current topic can be placed in a TWiki skin so that the URL can easily be read by smart phones. We use symbol version 8, e.g. the URL cannot be longer than 152 characters. @@ -166,6 +166,7 @@ | ==data/TWiki/%TOPIC%.txt== | Plugin topic | | ==data/TWiki/VarQRCODE.txt== | QRCODE variable documentation topic | | ==lib/TWiki/Plugins/%TOPIC%.pm== | Plugin Perl module | + | ==lib/TWiki/Plugins/%TOPIC%/Core.pm== | Plugin core module | | ==pub/TWiki/%TOPIC%/twiki-logo-80x40-t.gif== | Logo file | | ==pub/TWiki/%TOPIC%/qrcode-example-*.png== | Example QR Code image files | * Set the ownership of the extracted directories and files to the webserver user. @@ -193,13 +194,14 @@ ---++ Plugin Info * One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: - * Set SHORTDESCRIPTION = Create QR Code (a 2D barcode) in TWiki pages, useful for mobile applications + * Set SHORTDESCRIPTION = Create QR Code (a matrix barcode) in TWiki pages, useful for mobile applications | Plugin Author: | TWiki:Main.PeterThoeny | | Copyright: | © 2011 TWiki:Main.PeterThoeny, [[http://twiki.net/][Twiki, Inc.]] <br /> © 2011 TWiki:TWiki.TWikiContributor | | License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) | -| Plugin Version: | 2011-02-11 | +| Plugin Version: | 2011-02-12 | | Change History: | <!-- versions below in reverse order --> | +| 2011-02-12: | TWikibug:Item6647: Lazy loading of core and CPAN modules for better performance when QRCODE is not used | | 2011-02-11: | TWikibug:Item6647: Added version="auto" | | 2011-02-09: | TWikibug:Item6647: Initial version | | TWiki Dependency: | $TWiki::Plugins::VERSION 1.1 | Added: twiki/branches/TWikiRelease05x00/QRCodePlugin/lib/TWiki/Plugins/QRCodePlugin/Core.pm =================================================================== --- twiki/branches/TWikiRelease05x00/QRCodePlugin/lib/TWiki/Plugins/QRCodePlugin/Core.pm (rev 0) +++ twiki/branches/TWikiRelease05x00/QRCodePlugin/lib/TWiki/Plugins/QRCodePlugin/Core.pm 2011-02-12 21:27:07 UTC (rev 20428) @@ -0,0 +1,84 @@ +# Plugin module for TWiki Enterprise Collaboration Platform, http://TWiki.org/ +# +# Copyright (C) 2001-2011 Peter Thoeny, pe...@th... +# Copyright (C) 2011 TWiki Contributors. All Rights Reserved. +# TWiki Contributors are listed in the AUTHORS file in the root of +# this distribution. NOTE: Please extend that file, not this notice. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. For +# more details read LICENSE in the root of this distribution. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# For licensing info read LICENSE file in the TWiki root. + +package TWiki::Plugins::QRCodePlugin::Core; + +use strict; + +require TWiki::Func; # The plugins API + +#========================== +sub handleQRCODE { + my( $session, $params, $theTopic, $theWeb ) = @_; + + my $text = $params->{_DEFAULT}; + my $pEcc = $params->{ecc} || 'M'; + my $pVer = $params->{version} || '8'; + my $pSize = $params->{size} || '4'; + + return "QRCode Plugin Error: QRCode text is missing." unless( $text ); + + require GD::Barcode::QRcode; + $pVer = 0 if( $pVer eq 'auto' ); + my $image; + eval { + $image = GD::Barcode::QRcode->new( $text, + {ECC => $pEcc, Version => $pVer, ModuleSize => $pSize} )->plot->png; + }; + return "QRCode Plugin Error: $@" if( $@ ); + + my( $dir, $fileName ) = _makeFilename( $theWeb, $theTopic, "$text-$pEcc-$pVer-$pSize" ); + + open( PNG, "> $dir/$fileName" ) + or return "QRCode Plugin Error: Can't write temporary file $fileName."; + binmode( PNG ); + print PNG $image; + close( PNG ); + + my $html = '<img src="' . TWiki::Func::getPubUrlPath() + . "/$theWeb/$theTopic/$fileName\" />"; + return $html; +} + +#========================== +sub _makeFilename +{ + my ( $web, $topic, $text ) = @_; + + my $dir = TWiki::Func::getPubDir() . "/$web"; + unless( -e "$dir" ) { + umask( 002 ); + mkdir( $dir, 0775 ); + } + $dir .= "/$topic"; + unless( -e "$dir" ) { + umask( 002 ); + mkdir( $dir, 0775 ); + } + + use Digest::MD5 qw(md5_hex); + my $md5 = md5_hex( $text ); + + my $name = "_QRCodePlugin_$md5.png"; + + return( $dir, $name ); +} + +#========================== +1; Modified: twiki/branches/TWikiRelease05x00/QRCodePlugin/lib/TWiki/Plugins/QRCodePlugin/MANIFEST =================================================================== --- twiki/branches/TWikiRelease05x00/QRCodePlugin/lib/TWiki/Plugins/QRCodePlugin/MANIFEST 2011-02-12 21:25:26 UTC (rev 20427) +++ twiki/branches/TWikiRelease05x00/QRCodePlugin/lib/TWiki/Plugins/QRCodePlugin/MANIFEST 2011-02-12 21:27:07 UTC (rev 20428) @@ -1,6 +1,7 @@ data/TWiki/QRCodePlugin.txt 0644 data/TWiki/VarQRCODE.txt 0644 lib/TWiki/Plugins/QRCodePlugin.pm 0644 +lib/TWiki/Plugins/QRCodePlugin/Core.pm 0644 pub/TWiki/QRCodePlugin/qrcode-example-1.png 0644 pub/TWiki/QRCodePlugin/qrcode-example-2.png 0644 pub/TWiki/QRCodePlugin/twiki-logo-80x40-t.gif 0644 Modified: twiki/branches/TWikiRelease05x00/QRCodePlugin/lib/TWiki/Plugins/QRCodePlugin.pm =================================================================== --- twiki/branches/TWikiRelease05x00/QRCodePlugin/lib/TWiki/Plugins/QRCodePlugin.pm 2011-02-12 21:25:26 UTC (rev 20427) +++ twiki/branches/TWikiRelease05x00/QRCodePlugin/lib/TWiki/Plugins/QRCodePlugin.pm 2011-02-12 21:27:07 UTC (rev 20428) @@ -24,12 +24,12 @@ require TWiki::Func; # The plugins API require TWiki::Plugins; # For the API version -use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION $debug $pluginName $NO_PREFS_IN_TOPIC ); +use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION $NO_PREFS_IN_TOPIC $pluginName $debug ); $VERSION = '$Rev$'; -$RELEASE = '2011-02-11'; +$RELEASE = '2011-02-12'; -$SHORTDESCRIPTION = 'Create QR Code (a 2D barcode) in TWiki pages, useful for mobile applications'; +$SHORTDESCRIPTION = 'Create QR Code (a matrix barcode) in TWiki pages, useful for mobile applications'; $NO_PREFS_IN_TOPIC = 1; $pluginName = 'QRCodePlugin'; @@ -54,60 +54,11 @@ #========================== sub _QRCODE { - my( $session, $params, $theTopic, $theWeb ) = @_; - - my $text = $params->{_DEFAULT}; - my $pEcc = $params->{ecc} || 'M'; - my $pVer = $params->{version} || '8'; - my $pSize = $params->{size} || '4'; - - return "QRCode Plugin Error: QRCode text is missing." unless( $text ); - - use GD::Barcode::QRcode; - $pVer = 0 if( $pVer eq 'auto' ); - my $image; - eval { - $image = GD::Barcode::QRcode->new( $text, - {ECC => $pEcc, Version => $pVer, ModuleSize => $pSize} )->plot->png; - }; - return "QRCode Plugin Error: $@" if( $@ ); - - my( $dir, $fileName ) = _makeFilename( $theWeb, $theTopic, "$text-$pEcc-$pVer-$pSize" ); - - open( PNG, "> $dir/$fileName" ) - or return "QRCode Plugin Error: Can't write temporary file $fileName."; - binmode( PNG ); - print PNG $image; - close( PNG ); - - my $html = '<img src="' . TWiki::Func::getPubUrlPath() - . "/$theWeb/$theTopic/$fileName\" />"; - return $html; +# my ( $session, $params, $theTopic, $theWeb ) = @_; + # Lazy loading, e.g. compile core module only when required + require TWiki::Plugins::QRCodePlugin::Core; + return TWiki::Plugins::QRCodePlugin::Core::handleQRCODE( @_ ); } #========================== -sub _makeFilename -{ - my ( $web, $topic, $text ) = @_; - - my $dir = TWiki::Func::getPubDir() . "/$web"; - unless( -e "$dir" ) { - umask( 002 ); - mkdir( $dir, 0775 ); - } - $dir .= "/$topic"; - unless( -e "$dir" ) { - umask( 002 ); - mkdir( $dir, 0775 ); - } - - use Digest::MD5 qw(md5_hex); - my $md5 = md5_hex( $text ); - - my $name = "_QRCodePlugin_$md5.png"; - - return( $dir, $name ); -} - -#========================== 1; |