<div dir="ltr">Hi,<div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 22, 2013 at 10:40 PM, Marcel de Rooy <span dir="ltr"><<a href="mailto:M.de.Rooy@rijksmuseum.nl" target="_blank">M.de.Rooy@rijksmuseum.nl</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">




<div>
<div style="direction:ltr;font-size:10pt;font-family:Tahoma">
<p><span style="font-size:10pt">Should we add a PERL rule that prohibits defining lexical variables (my $var) at the outermost block (file level) ?</span></p></div></div></blockquote><div>-1 for scripts -- it's not necessary, and doing anything to tempt folks to use 'our' unnecessarily instead would be worse.  It's sufficient to ensure that any subroutines inside the file aren't inappropriately accessing file-level lexicals, and that's easy to test by verifying that the following doesn't emit any warning messages:</div>

<div><br></div><div>perl -MCGI::Compile -e 'my $sub = CGI::Compile->compile($ARGV[0])' /path/to/<a href="http://script.pl" target="_blank">script.pl</a><br></div><div><br></div><div>How are we doing at the moment, for CGI scripts)?  Not badly, actually:</div>

<div><br></div><div><a href="http://paste.koha-community.org/223" target="_blank">http://paste.koha-community.org/223</a><br></div><div><br></div><div>A provisional +1 for modules, where use of a package-level lexical is a signal that state may be held on to inappropriately.  Running the CGI::Compile test on *.pm files can point out the most egregious examples, though.  As it turns out, C4 is doing less badly than I would have expected:</div>
<div><br></div><div><a href="http://paste.koha-community.org/224">http://paste.koha-community.org/224</a><br></div><div><br></div><div>Even for modules, though usage of 'our' should be discouraged except for VERSION and the like.</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div style="direction:ltr;font-size:10pt;font-family:Tahoma">
<p>Is it also needed to move script subroutines to module level?</p></div></blockquote><div><div>This would have to be handled carefully -- for example, to take it to an extreme, a rule that "scripts cannot have subroutines" would be problematic.  While there are undoubtedly plenty of routines that currently live in scripts that could be generalized and moved into the Koha namespace, sometimes a script really ought to have subroutines purely for the sake of good organization, even if those subroutines have no utility outside of that particular script.  There are plenty of legacy scripts that never managed even plain old functional decomposition; and I would hate to see anything that would (even inadvertently) discourage appropriate use of local subroutines.</div>

<div><br></div><div>The key word is "appropriate" -- an internal subroutine that doesn't touch variables that are not directly passed to it is fine, of course.</div></div><div> </div></div><div>Regards,</div>

<div><br></div><div>Galen</div>-- <br><div dir="ltr"><div>Galen Charlton</div><div>Manager of Implementation</div><div>Equinox Software, Inc. / The Open Source Experts</div><div>email:  <a href="mailto:gmc@esilibrary.com" target="_blank">gmc@esilibrary.com</a></div>

<div>direct: <a href="tel:%2B1%20770-709-5581" value="+17707095581" target="_blank">+1 770-709-5581</a></div><div>cell:   <a href="tel:%2B1%20404-984-4366" value="+14049844366" target="_blank">+1 404-984-4366</a></div><div>
skype:  gmcharlt</div><div>web:    <a href="http://www.esilibrary.com/" target="_blank">http://www.esilibrary.com/</a></div><div>Supporting Koha and Evergreen: <a href="http://koha-community.org" target="_blank">http://koha-community.org</a> & <a href="http://evergreen-ils.org" target="_blank">http://evergreen-ils.org</a></div>

</div>
</div></div>