Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

autoloading functions from a text string

by hackmare (Pilgrim)
on Feb 14, 2002 at 19:44 UTC ( #145539=perlquestion: print w/replies, xml ) Need Help??

hackmare has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

I have a fear. A fear of the darkness of the unknown, of the listlessness that impurity of mind and flimsiness of knowledge causes my frail frame.

A module exists which uses autosubs:

--------------------------

package SVG::Element;

$VERSION = "1.0";

use strict;
use vars qw(@ISA $AUTOLOAD %autosubs);
#@ISA = qw( SVG::XML );
use SVG::XML;

my @autosubs=qw(
   sub1 sub2 sub3
);

%autosubs=map { $_ => 1 } @autosubs;

#- - - - - - - - -

sub new ($$;@) {
    my ($proto,$name,%attrs)=@_;
    my $class=ref($proto) || $proto;
    my $self={-name => $name};
    foreach my $key (keys %attrs) {
        next if $key=~/^\-/;
        $self->{$key}=$attrs{$key};
    }
    
    return bless($self,$class);
}

--------------------------

Now what I would like to do is define the names of the subs sub1 sub2 sub3 externally (say, within a file)

And this is where my knowledge of Perl falls down really hard. I would like the subs to be the names of a subset of html tags, such as qw(a href html head ul ol li p h1 h2 b i) for example, ignoring that some of these may be reserved words (or not).

Now here is the crux...

I have no idea to pass the name of the file that contains this list to the program so that it is dymanically generated.
is that even possible? I would prefer to pass it through the constructor. But How do I do that before the object is even instantiated? There must be _smoe_ way to pass the data through. The only thing that I can think of is to generate a list of modules, each module which does the autoloading for its own function set.

The second issue is that I do not want to recompile the script everytime it runs. I would like it to run with a single setup file and keep going with that without having to go through a recompilation each time it is invoked.
Is that possible? Is it even an issue?

Thank you for your wise consideration

Hackmare

  • Comment on autoloading functions from a text string

Replies are listed 'Best First'.
Heeeelllp!! (A second cry for help - Re: autoloading functions from a text string)
by hackmare (Pilgrim) on Mar 01, 2002 at 14:41 UTC

    I am saddened, for this is the first time that while I seek the light of knowledge from the monastary, I trip over the root of is my own ignorance, and that of my bretheren.

    Nobody seems to have an answer to this post. Perhaps I will have to do more reading. I think this is the first time I've asked a question that is either too hard or so pedantic that nobody deigns to soil their pen over it.

    I have made nary any progress regarding this trecherous question and am beginning to dispair that the knowledge I seek exists not.

    Again, the question I seek an answer to is simple, I think:
    How do I dynamically define the values sub1,sub2,sub3 in the example above such that I can define them through the new() constructor? The idea would be to pass a file name to the constructor and have it define the

    Maybe I can directly invoke the @isa array within the constructor, rather in front of it?

    hackmare.

Re: autoloading functions from a text string
by particle (Vicar) on Mar 01, 2002 at 17:24 UTC
    your question will not go unanswered. i have heard your screams throughout the monestary. have patience, brother hackmare. reading up on do and eval will allay your fear. find solace here.

    ~Particle ;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://145539]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2020-02-18 00:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (74 votes). Check out past polls.

    Notices?