Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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?

Replies are listed 'Best First'.
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?

        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.


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://906759]
[jedikaiti]: Hi Monks

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2018-01-22 17:21 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (235 votes). Check out past polls.