On Jan 28, 2004, at 11:24 PM, [EMAIL PROTECTED] wrote: [..]
my circumstance is that I have a 10,000 line standalone command-line Perl program which I am refactoring into working as both a web app (Apache+Mod_perl+MySQL) and a command-line app. I'm not yet clear on what either the file or object architecture will be, which is why I'm not carving pieces out into separate files quite yet. All of the code written so far is pretty tightly coupled, again making it nontrivial to partition. It also has some long CPU-bound computation sequences, and I'm reluctant to make changes which would add overhead.
ouch. Given this context it makes some reasonable sense why you were trying to solve it all in one file. But you may need to rethink your strategy a bit here, and work on the slow and steady decoupling of the code so that you wind up with two different code lines and their supporting common collection of perl modules.
foo_cli - the classical command line code foo_web - the web based app
both of which use the Foo::Monkey suite of modules.
This way you can work out what will really be required to be added to the web app itself...
[..]
I also find that it's really convenient, for now, to have all my source in one file (at least until I'm sure of the new architecture), for the same reason that someone on the list has advocated merging all the perl docs into a single file: for supereasy search and, in my case, replace. Also, as I transition into a packaged system of namespaces, I have a lot of code that expects a lot of names to be omnipresent (about 250 total subs, maybe half as object methods and half plain old subroutines); again it might be convenient to be able to put names in packages but still have them omnipresent until I'm clear how it all fits together.[..]
with 250 subs you will want to sort out which of them have clean API's and as such can be easily pulled out as is. By clean, I mean they are not expecting anything to have water falled into them, nor are they doing the side effect of setting things "globally" that were not passed into them.
I can appreciate the idea that it is easier to hunt them down in one file in one editor - but you might want to also look at the advantage of having more than one file open in more than one editor...
But as japhy has already noted, if you want to put it all into one file you can use the BEGIN block and then start sorting out your package spaces:
SomePackage->import('foo'); foo(); FOO::Bar->foo("bed time again");
BEGIN { package SomePackage; require Exporter; our @ISA = 'Exporter'; our @EXPORT = 'foo'; sub foo { print "foo!\n" }
package FOO::Bar; sub foo { my ($me,$arg) = @_; print "have arg: $arg\n"; } }
ciao drieux
---
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>