in reply to Re: How do you say, in Perl....
in thread How do you say, in Perl....

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?

Replies are listed 'Best First'.
Re^3: How do you say, in Perl....
by Anonymous Monk on May 26, 2011 at 10:21 UTC

      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.

Re^3: How do you say, in Perl....
by oxone (Friar) on May 26, 2011 at 10:18 UTC
    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; }