What do can I do to keep the inherited naming structure and autoload the tie routines? Can I put multiple package statements/sections in my one ABC.pm file?
Yes, though it can get a little messy. For example, you could call this module
package Foo; use strict; use warnings; package Foo::Bar; use strict; use warnings; sub foo { print 'foo'; } return 1;
with the script
use Foo; use strict; use warnings; Foo::Bar->foo;
Note that you cannot use Foo::Bar since the file does not exist. The Foo use statement loads Foo::Bar into the namespace. (-- Not quite true: see below)
52 of them make autoloading seem worthwhile. Although if they are in separate packages, each one containing only the tie routines for one "tie-to" name, maybe autoloading isn't worthwhile?
You can use a base class (i.e. ISA) to define your autoload routines, so no matter how many files you have, the actual code is localized. A good intro (if you need it) on constructing a base class for exactly this is found in perltoot.
Update: As a template for the autoload code, I give you a modified module
package Foo; use strict; use warnings; our $AUTOLOAD; sub AUTOLOAD { my $self = shift; my $class = ref($self) || $self; my $name = $AUTOLOAD; print "$name in $class\n"; } package Foo::Bar; use strict; use warnings; use Exporter; our @ISA = qw(Foo); sub foo { print "foo\n"; } return 1;
and script
use Foo; use strict; use warnings; Foo::Bar->foo; Foo->bar; Foo::Bar->bar;
Now if you'll excuse me, I have some documentation to read -- ikegami just blew my mind.
In reply to Re: Autoloading tie routines
by kennethk
in thread Autoloading tie routines
by cmac
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |