Please explain "Furthermore ABC looks like an example of the God module anti-pattern. That is a code smell right there." Colorful language!

Obviously there are is a lot of stuff in XYZ::ABC, but I'm working toward a successor module to an existing CPAN module, which has the same Scalar, Hash, and BTree stuff. I admit to making it worse by adding the Array stuff. But hopefully the linker will treat the ABC.so file as a library, and only load what's called for.

"everything that the AUTOLOAD has done with those 6 packages"? (There are now 8 because I added BTree as an alias for Hash, to be more compatible with the predecessor module.) Far as I know, AUTOLOAD has done nothing but be there to field attempts to use unknown constants and subroutines. The subsidiary package names cannot be use'd, and exist only to be used in tie statements.

There is no "use AutoLoad" in ABC.pm any more. ABC.pm's AUTOLOAD is free-standing, and passes the tie calls to subs in ABC.xs that are also available as direct calls to users of XYZ::ABC.

Rather than define 82 names in the symbol table at the start of execution, the compromise course between your routine and the direct-through AUTOLOAD that for the moment is still shown below, is for AUTOLOAD to put each name for which it is called in the symbol table (thus eliminating future calls to AUTOLOAD for this name) and then go to the newly defined sub. It will need to make an anonymous sub that dereferences the first operand from perl to match what the destination XS routine expects.

If I wasn't "confused about how this works" I wouldn't be posting to perlmonks. ABC.pm does not have an import method. It has an export method that used to include AUTOLOAD in @EXPORT_OK. But I took the use's out of the subsidiary packages, and no longer export AUTOLOAD. Thank you for this!

We must be careful about commenting about the clarity of each others' code. I find your routine above quite readable, until I come to *name = thing; which I have not used. Based on your code I made several improvements to my AUTOLOAD routine, which looks like this PENDING THE "STORE THE NAME" IMPROVEMENT NOTED ABOVE:
# 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 { # make the base name (without the "package::") (my $constname = $AUTOLOAD) =~ s/.*:://; # call the constant lookup routine in ABC.xs my $val = constant($constname, 0); if ($!) { # the name in $AUTOLOAD is not a constant defined by XYZ::ABC # sah = scalar/array/hash if (my ($abcx, $sah, $function) = $AUTOLOAD =~ /^XYZ::(ABCA?)::(Scalar|Array|Hash|BTree)::([ +A-Z]+)$/) { if ($sah eq 'BTree') {$sah = 'Hash'} if ($function eq uc("TIE$sah")) { my $self = shift; my $base_sah = shift; # sah = scalar/array/hash return bless \$base_sah, $self; # Scalar or Array or Hash } elsif ($function eq 'FETCH' || $function eq 'STORE' || $sah ne 'Scalar' # Array or Hash && $function =~ /^(DELETE|EXISTS|CLEAR)$/ || $sah eq 'Array' && $function =~ /^(FETCHSIZE|STORESIZE|EXTEND|POP|PU +SH|SHIFT|UNSHIFT|SPLICE)$/ || $sah eq 'Hash' && $function =~ /^(FIRSTKEY|NEXTKEY|SCALAR)$/) { $function =~ s/KEY$/_KEY/; my $subname = lc($abcx) . '_' . lc($sah) . '_' . lc($f +unction); my $base_sah_ref = shift; unshift @_, $$base_sah_ref; # dereference the base sca +lar/array/hash goto &$subname; } elsif ($function eq 'UNTIE' || $function eq 'DESTROY') { return; # do nothing } } 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? }
I would appreciate comments on the last two questions in its comments.

Thanks for being there,
cmac
www.animalhead.com

In reply to Re^6: 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.