Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by NetWallah (Abbot)
on Jun 27, 2012 at 03:11 UTC ( #978552=note: print w/ replies, xml ) Need Help??


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

How about method-chaining - you can Chain the timeout method when you need it :

use strict; use warnings; {package This; sub new{ my ($class, %att )=@_; return bless {%att}, $class; } sub with_timeout{ my ($self, $timeout) = @_; $timeout or die "Timeout not specified"; return bless {%$self, TIMEOUT=>$timeout},__PACKAGE__; } sub do_work{ my ($self) = @_; for my $k(sort keys %$self){ print "$k \t=>" . ( $self->{$k}||"Undef*") . "\n"; } } 1; } my $t = This::->new (CANDY=>'Mint'); print "-- First call - no TIME--\n"; $t->do_work(); print "-- adding time--\n"; $t->with_timeout(10)->do_work(); print "-- this should not have it--\n"; $t->do_work();

             I hope life isn't a big joke, because I don't get it.
                   -SNL


Comment on Re: Style - how to give class method call as parameter
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2015-07-04 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls