What about running the tests, then modifying the sub, then running again? Here's a quickly thrown together example (in this example I simply mock out the whole function) to see if this is more along the lines of what you're looking for:
package Package; {
sub perform {
return $_[0] + $_[1];
}
}
package main; {
use Mock::Sub;
use Test::More;
tests();
my $m = Mock::Sub->new;
my $changed = $m->mock('Package::perform');
$changed->return_value($_[0] - $_[1]);
tests();
done_testing();
sub tests {
is Package::perform(5, 5), 10, "5 + 5 = 10";
}
}
Output:
ok 1 - 5 + 5 = 10
not ok 2 - 5 + 5 = 10
# Failed test '5 + 5 = 10'
# at pack.pl line 24.
# got: '0'
# expected: '10'
1..2
# Looks like you failed 1 test of 2.
If this example is more along the lines you're after (modifying code on the fly), my Devel::Examine::Subs is designed to alter code within a file (so say you wanted to modify a single line in a single sub within a package, you could (then revert it back), and I could write a mock up example of what it may look like. But perhaps I'm way off here.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|