However, the number of 'process' functions that I might generate are not limited, and that means that every time I add a new module with a new process, I'd have to modify the data type code in addition to add this feature, which is a nuisance.

Sounds like you might need a smart AUTOLOAD. Consider a scenario where you have a registry of "process functions" on disk, where the registry is a flat file database with pairs of "function-name, filename" as tuples. When AUTOLOAD is triggered, it scans this registry to locate the file that corresponds with a process function. When it finds one, it loads the file into a string, then evals it (as a sub definition) into the dataset's namespace.

This approach would let you (or others) write new process functions in files external to your main body of code. For extra credit, you could provide an option in your main script to use a different, "debug" registry that you would use for debugging new functions.

Here's an untested fragment, pieced together from pages 468-471 of the Cookbook.

sub AUTOLOAD { my $self = shift; my $attr = $AUTOLOAD; $attr =~ s/.*:://; # open the registry, search for $attr, # open assocated filename and load the # contents into $sub no strict 'refs'; *$attr = eval $sub; goto &$attr; }
Good lord, I just used a goto.


In reply to Re: Possible Stupid Perl Trick - Importing method into object class? by dws
in thread Possible Stupid Perl Trick - Importing method into object class? by Masem

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.