Kalle Hallivuori > Test-CallFlow-0.03 > Test::CallFlow::Call

Download:
Test-CallFlow-0.03.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  7
Open  0
View/Report Bugs
Source  

Test::CallFlow::Call ^

SYNOPSIS ^

  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[0] did not match check #$mismatch[1]\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;

PROPERTIES ^

args
  [ '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.

results
  [ [ '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.

min

Minimum number of calls required for this call to be satisfied.

max

Maximum number of calls to allow.

called

Number of times this call has been made.

anytime

When true, this call may be made any time rather than at a specific step.

debug

When true, some helpful messages are printed.

METHODS ^

new

  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.

result

  $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.

Returns self.

result_from

  $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.

Returns self.

anytime

Causes this call to be callable at any time after its declaration, rather than at that exact point in call order.

Returns self.

min

  $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.

max

  $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.

end

  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.

Returns self.

satisfied

  die "Not enough calls made" unless $call->satisfied;

Returns true when enough calls have been made.

over

  die "No more calls can be made" if $call->over;

Returns true when no more calls can be made.

in_order

Returns true if this call must be made in order, false if it can be made at any time.

check

  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.

call

  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.

called_from

  $call->called_from( "subname" );

Sets calling context reported by name().

Returns self.

name

  print "Calling ", $call->name, "\n";

Returns a user-readable representation of this call.

reset

  $call->reset;

Resets the call object to pre-run state.

syntax highlighting: