sub spiffy_little_function { my ($x,$y) = @_; my @params; # parameters to Foo::new my $o; # an object of class Foo my $z; # computed result before taxes my $t; # computed result after taxes @params=get_huge_list_of_parameters($x); $o = Foo->new(@params); $z=$o->compute_result($y); $t = $z * 0.10; return($t) } #### # test spiffy_little_function with options 'foo' and 'bar'

# make test run faster by eliminating slow function call redefine_function("main::get_huge_list_of_params", sub {} );

# use minimal constructor redefine_function("Foo::new",sub { return bless {},"Foo" });

# This method should be called with "bar", and return 42, # for the purposes of this test. redefine_function("Foo::compute_result", sub { 42 } );

$result = spiffy_little_function("foo","bar") is($result,4.2,"spiffy_little_function:foo bar test");

restore_all_functions(); #### redefine_function(Foo::compute_result, sub { is($_[0],"bar","spiffy_little_function passed right value to compute_result") return(42); }