mark@DRD.Com (Mark Lawrence) (07/12/90)
The subject line says it all -- I want to use packages in the way they were intended and I'd like to be able to use the debugger in a script that uses packages. I admit that my concept of how packages were intended to be used may be bogus. The man page says they give a local namespace to the enclosing block so as not to conflict with namespaces of callers (hence, safe re-useability). As an added bonus, they can be put into separate files that other scripts can 'do' (to get the code interpreted in) so that common subs can be made generally available. So, I write myself a few packages to perform operations common to a number of scripts: foo.pl, bar.pl and gex.pl foo.pl: bar.pl: gex.pl: package foo; package bar; package gex; sub foo'DoThis { sub bar'Snicker{ sub main'gex{ ... ... ... } } } sub bar'Snort{ ... } In an example script, towards the top, I say: do 'gex.pl'; do 'bar.pl'; do 'foo.pl'; and then when I want to call one of the functions, I say: do main'gex(args); do bar'Snort(args); # and so forth (The `main' qualifier in gex.pl, BTW, is there on purpose: we actually have a package that does this, because of the example with package dumpvar in the Packages section of the man page. Why use a package if you're not going to take advantage of the alternative namespace? Or am I really confused?) When I fire the script up in the debug mode, I say: c ## where the line number is past the do 'file' type of calls and past one of the lines in which we actually call a sub defined in a function and I get: Undefined subroutine "Snort" called at Script.pl line ## ... I guess it makes sense to me that Snort is an undefined symbol in the `main' namespace, but shouldn't the debugger handle that (especially since in code I qualify it properly?) How do I debug this so that I can 'step' into packages and watch them execute? Now, I just read the package into my file, comment out the package lines and remove the qualifiers and then test the script as if all subs were 'local', as it were. Isn't there a better way? -- mark@DRD.Com uunet!apctrc!drd!mark$B!J%^!<%/!!!&%m!<%l%s%9!K(B "...do justice, love mercy, and walk humbly..." Micah 6:8
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (07/17/90)
In article <1990Jul12.143602.23401@DRD.Com> mark@drd.Com (Mark Lawrence) writes:
: The subject line says it all -- I want to use packages in the way they
: were intended and I'd like to be able to use the debugger in a script
: that uses packages.
I'd like to be able to do that too. It's on my Todo list, somewhere.
: (The `main' qualifier in gex.pl, BTW, is there on purpose: we actually have
: a package that does this, because of the example with package dumpvar in the
: Packages section of the man page. Why use a package if you're not going
: to take advantage of the alternative namespace? Or am I really
: confused?)
The packaging applies to any variables referenced as well as the subroutine
names, so you might well want to declare main'subroutine in a package that
only wants to make the subroutine name available but not any "local globals".
Abstract types often want to have private data but public operations.
: "...do justice, love mercy, and walk humbly..." Micah 6:8
I think the last is the hardest.
Larry