Based on the the statement "the AUTOLOAD sub is called with the arguments that the unknown sub would be called with", here is my AUTOLOAD in ABC.pm.
# AUTOLOAD is used to # 1) 'autoload' constants from the constant() function in ABC.xs # If the name is not a constant then it's parsed for # 2) a tie package-name::function-name, which if matched is executed our $AUTOLOAD; # implicit argument of AUTOLOAD sub AUTOLOAD { my $constname; ($constname = $AUTOLOAD) =~ s/.*:://; my $val = constant($constname, 0); if ($!) { # the name in $AUTOLOAD is not a constant defined by XYZ::ABC if (my ($kind, $nolock, $function) = $AUTOLOAD =~ /^XYZ::ABC::(Scalar|Array|Hash)::(NoLock::)?( +[A-Z]+)$/) { if ($function =~/^TIE$kind$/i) { my $self = shift; my $sah = shift; # sah = scalar/array/hash return bless \$sah, $self; # vv Scalar or Array or Hash } elsif ($function =~ /^(FETCH|STORE)$/ || $kind !~ /^S/ # vv Array or Hash && $function =~ /^(DELETE|EXISTS|CLEAR)$/ || $kind =~ /^A/ # vv Array && $function =~ /^(FETCHSIZE|STORESIZE|EXTEND|POP|PU +SH|SHIFT|UNSHIFT|SPLICE)$/ || $kind =~ /^H/ # vv Hash && $function =~ /^(FIRSTKEY|NEXTKEY|SCALAR)$/) { my $subname = 'abc' . ($nolock ? 'a_' : '_') . lc($kin +d) . '_' . lc($function); my $sah_ref = shift; { no strict 'refs'; # differentiate subs with and without return value +s if ($function =~ /^(ST|CL|PU|UN|EXT)/) { &$subname ($$sah_ref, @_); return; } else { return &$subname ($$sah_ref, @_); } } } elsif ($function =~ /^(UNTIE|DESTROY)$/) { # how do we do nothing? return; # ?? } } croak "$AUTOLOAD is not a defined constant or subroutine for X +YZ::ABC"; } # the name in $AUTOLOAD is a constant defined by XYZ::ABC: define +it for perl eval "sub $AUTOLOAD { $val }"; # can this be $constname rather tha +n $AUTOLOAD? goto &$AUTOLOAD; # can this just be 'return' if all of the defined + names really are constants? }
The routines that implement most of the 'tie' calls already exist in ABC.xs, with the same names (lowercased). It pleases me very much to get rid of 52 silly wrapper routines.

At the end of ABC.pm are six packages like this:
package XYZ::ABC::Scalar; use XYZ::ABC qw(AUTOLOAD); our @ISA = qw(XYZ::ABC); # are this and the use both needed? 1;
Suggestions and corrections for AUTOLOAD and these packages are very welcome. In its first test AUTOLOAD allowed perl to do a tie statement to XYZ::ABC::Scalar.

Thanks for being there,
cmac
www.animalhead.com

In reply to Re^4: Autoloading tie routines by cmac
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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.