my $call = Test::CallFlow::Call->new( args => [ 'My::Pkg::Method', 'an argument' ] )->result(12765); my @mismatch = $call->check( 'My::Pkg::Method', 'an argument' ) and die "Argument #$mismatch did not match check #$mismatch\n"; my $result = $call->call; # returns 12765 print "Enough calls made\n" if $call->satisfied; print "No more calls could be made\n" if $call->over;
[ 'Package::Method', "static argument", ... ]
Reference to an array containing full method name and argument checkers: static values to compare against or Test::CallFlow:ArgCheck subclasses to use for comparison.
[ [ 'first result' ], [ 'second result' ], [ 'result for any subsequent calls' ] ]
Reference to an array of arrays, each containing the result returned from a call to this mock.
Minimum number of calls required for this call to be satisfied.
Maximum number of calls to allow.
Number of times this call has been made.
When true, this call may be made any time rather than at a specific step.
When true, some helpful messages are printed.
my $call = Test::CallFlow::Call->new( args => [ 'full::sub_name', qw(arguments to match), Test::CallFlow::ArgCheck::Regexp->new( qr/arg regex/ ) ] );
Returns a new
Test::CallFlow::Call object with given properties.
$call = $call->result( 'foo', 'bar', 'baz', 'quu' );
Adds a result for a call. Multiple values will be returned as an array in array context. Multiple result sets can be defined for a repeated call.
$call = $call->result_from( \&result_provider_sub );
Adds a result provider for a call.
A result provider will be called whenever a result is required. It will get as parameters the original call.
Causes this call to be callable at any time after its declaration, rather than at that exact point in call order.
$call->min(0)->max(2); die "must be called" if $call->min;
When called with a value, set minimum number of calls required to given value and return self. When called without a value, returns the current minimum number of calls; default is number of specified results.
$call->max(2)->min(0); die "no results available" unless $call->max;
When called with a value, set maximum number of calls possible and return self. When called without a value, returns the current maximum number of calls. Default is 1 or bigger of minimum and number of results.
mock_package( 'Foo' ); my @optionals = ( Foo->get->anytime->min(0), Foo->set->anytime ); Foo->may_be_called->min(0); # ordered, skipped unless called Foo->shall_be_called->end( @optionals ); # will croak about uncalled Foo->set
Given calls that could be made at any time are no more callable. If any of them are uncalled when this call is matched, optional ones are discarded silently, required ones cause dying with stack trace in Test::CallFlow::Plan::call.
die "Not enough calls made" unless $call->satisfied;
Returns true when enough calls have been made.
die "No more calls can be made" if $call->over;
Returns true when no more calls can be made.
Returns true if this call must be made in order, false if it can be made at any time.
die "Arg #$arg failed to match arg check #$check" if my ($arg, $check) = $call->check( [ $sub, @args ] );
Returns nothing on success. On failure, returns position of failed argument and position of the test it failed against.
my $result = $call->call;
Returns next result of this call, nothing if result not set.
Dies if call has been executed more than maximum times.
$call->called_from( "subname" );
Sets calling context reported by
print "Calling ", $call->name, "\n";
Returns a user-readable representation of this call.
Resets the call object to pre-run state.