Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found