The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::AutoMock::Mock::Overloaded - Mock that supports operator overloading

SYNOPSIS

  use Test::AutoMock qw(mock_overloaded manager);
  use Test::More import => [qw(is done_testing)];

  my $mock = mock_overloaded;

  # define operators, hashes, arrays
  manager($mock)->add_method('`+`' => 10);
  manager($mock)->add_method('{key}' => 'value');
  manager($mock)->add_method('[0]' => 'zero');

  # call overloaded operators
  is($mock + 5, 10);
  is($mock->{key}, 'value');
  is($mock->[0], 'zero');

  # varify calls
  manager($mock)->called_with_ok('`+`', [5, '']);
  manager($mock)->called_ok('{key}');
  manager($mock)->called_ok('[0]');

DESCRIPTION

It is a subclass of Test::AutoMock::Mock::Basic that supports operator overloading.

Do not instantiate this class directly. Use Test::AutoMock::mock_overloaded instead.

SPECIAL METHODS

This class supports special notation methods. It can be used with methods such as manager($mock)->called_ok and manager($mock)->add_method.

OPERATOR OVERLOADING

The method name enclosed in back-tick (`) means operator overloading. The operator name is the same as the overload module.

Most operator overloads return child AutoMock, just like regular methods. The following methods return default values that match type. Please overwrite it if necessary.

`bool` : !!1
`""` : a unique name of instance
`0+` : 1
`qr` : qr//

Also, in order to avoid infinite loops, `<>` defaults to undef.

There are two arguments to be recorded, $other and $swap, according to the overload module specifications. Please be careful when using automock_called_with_ok.

Below is a complete list of possible names.

`+`, `-`, `*`, `/`, `%`, `**`, `<<`, `>>`, `x`, `.`
`+=`, `-=`, `*=`, `/=`, `%=`, `**=`, `<<=`, `>>=`, `x=`, `.=`
`<`, `<=`, `>`, `>=`, `==`, `!=`
`<=>`, `cmp`
`lt`, `le`, `gt`, `ge`, `eq`, `ne`
`&`, `&=`, `|`, `|=`, `^`, `^=`
`neg`, `!`, `~`
`++`, `--`
`atan2`, `cos`, `sin`, `exp`, `abs`, `log`, `sqrt`, `int`
`bool`, `""`, `0+`, `qr`
`<>`
`-X`
`${}`, `*{}`

@{} and %{}, &{} are not supported. see "HASH, ARRAY, CODE ACCESS" instead.

HASH, ARRAY, CODE ACCESS

In this class, you can handle operations with the same notation as hash-ref, array-ref, code-ref.

[index], FETCHSIZE, STORESIZE, CLEAR, PUSH, POP, SHIFT, UNSHIFT, DELETE, EXISTS

This name is used when the mock is called as an array reference. See Test::AutoMock::Mock::TieArray for details.

{key}, DELETE, CLEAR, EXISTS, FIRSTKEY, NEXTKEY, SCALAR

This name is used when the mock is called as an hash reference. See Test::AutoMock::Mock::TieHash for details.

()

This name is used when the mock is called as a code reference. You can also access its arguments.

LICENSE

Copyright (C) Masahiro Honma.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Masahiro Honma <hiratara@cpan.org>