Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How do you say, in Perl....

by SilasTheMonk (Chaplain)
on May 26, 2011 at 07:03 UTC ( #906759=note: print w/ replies, xml ) Need Help??


in reply to How do you say, in Perl....

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?


Comment on Re: How do you say, in Perl....
Re^2: How do you say, in Perl....
by willymacoy (Acolyte) on May 26, 2011 at 09:58 UTC

    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; }

        Module::Pluggable - perfect. Dispatch table - yep I can see how I might use that. Abstract factory pattern - this looks quite cool and I think I'll sit down one day and play with it.

        Thanks.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-10-23 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (123 votes), past polls