Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Style - how to give class method call as parameter

by Corion (Pope)
on Jun 26, 2012 at 13:47 UTC ( #978427=note: print w/ replies, xml ) Need Help??

in reply to Style - how to give class method call as parameter

Personally, I like number three best, but as an alternative, you can wrap number three in some syntactic sugar:

sub transaction(&$$) { my ($cb, $self,$timeout) = @_; $self->do_sub_with_timeout( $cb, $timeout ); }; transaction { $deployer->extend_order_lease( $order, $end_date ); } $self, $timeout;

Unfortunately, the & prototype must come as the first argument. I'm also not convinced that this style is less confusing/more readable than the other.

Comment on Re: Style - how to give class method call as parameter
Select or Download Code
Replies are listed 'Best First'.
Re^2: Style - how to give class method call as parameter
by strat (Canon) on Jun 26, 2012 at 18:23 UTC

    Well, I reply to Corion's posting although it becomes a general reply to all who replied ;-)

    Thank you very much for your replies. I hoped for a beautiful way to write this, but I will use version 3 since it looks less ugly than the other two ways.

    Adding a timeout-parameter to extend_order_lease would be best. But I don't dare to change the external framework or Boldra would look at me with very sad eyes the whole day long ;-)

    The synthetic sugar with the prototype looks nice, but in my case I don't want to use it. I put the methods do_sub_with_timeout or do_method_with_timeout into a Moose role so we can be use them everywhere in our framework (in the moment in about 4 different classes), and so I want them to be methods and not subs for not to need import subs into a foreign namespace. (And methods ignore prototypes anyway.)

    Have a nice evening

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8."

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2015-11-25 21:35 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (691 votes), past polls