Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

How do you say, in Perl....

by willymacoy (Acolyte)
on May 26, 2011 at 04:01 UTC ( [id://906746]=perlquestion: print w/replies, xml ) Need Help??

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

I have come here for a few terms and concepts that I can chase down. If anyone can help, thanks in advance.

I wish to write a generic module that will take a undefined (in the unknown sense, rather than the undef sense) hash reference as a parameter. It will return a single value. The module will call, on a per machine basis, any other modules, or functions, that the user has decided need calling. The generic module needs to find these called modules by itself (kind of like Linux startup scripts) and load them (and preferably keep them loaded because they will be called aplenty).

What Perl concepts do I have to chase down to be able to do this?

Thanks

Replies are listed 'Best First'.
Re: How do you say, in Perl....
by SilasTheMonk (Chaplain) on May 26, 2011 at 07:03 UTC
    The question seems pretty vague to me. I have the impression you are trying to do some sort of magic but aren't too clear what. Could you actually try and state what problem you are trying to solve?

      I have a message I wish to send. I wish to sign it depending on the content of the message. There will be a default signature. But, if the user wishes he may intercept the signature routine and provide a different signature, by providing another module that is called by the signature routine - if it exists.

      The programming of the signature routines is quite basic. It is just the strategy of having them called without the calling code explicitly call them. After all, I don't know what they are going to be, just that they might be.

      Does that make sense?

        You might want to pass in a code ref instead of a hash ref, and then in your function you can say:
        my $signature = $custom_coderef ? $custom_coderef->() : default_sig();
        The code ref itself can require any modules it needs, eg:
        my $coderef = sub{ require Foo::Bar; my $signature = "blah"; return $signature; }
Re: How do you say, in Perl....
by Anonymous Monk on May 26, 2011 at 04:34 UTC
Re: How do you say, in Perl....
by sundialsvc4 (Abbot) on May 26, 2011 at 11:38 UTC

    The general notion of “wrapping things,” ... the so-called “onion approach” ... might be the sort of thing that you are looking for.   As an example of the idea, look at Plack::Builder, which is part of a so-called “web server super-glue” system that needs a lot of flexibility.   (Nevermind the system.   Observe the concept and its implementation.   By the way, “DSL” means “domain-specific language,” which was a new terminology to me.)

    Before pursuing strategies like, “I wish to write a generic module that will take a hash reference as a parameter ...” it is usually wisdom to initially restrain such thoughts and let your CPAN do the walking before you let your fingers do the typing.   Presume that you will probably be able to find something that is suitable without having to build it.   Not always the case, but usually a fruitful way ... in my experience, a much more fruitful way ... to arrange your initial thoughts regarding a problem like this one.   Or I think so, anyway...

    (And if you do come up with something original and stunning ... “Wow!   Your first CPAN contribution!   Gee, thanks!!”   Lookin’ forward to it ... seriously.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-19 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found