Test::AutoMock::Mock::Overloaded - Mock that supports operator overloading
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]');
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.
This class supports special notation methods. It can be used with methods such as manager($mock)->called_ok and manager($mock)->add_method.
manager($mock)->called_ok
manager($mock)->add_method
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
`""`
`0+`
1
`qr`
qr//
Also, in order to avoid infinite loops, `<>` defaults to undef.
`<>`
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.
$other
$swap
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`
`-X`
`${}`
`*{}`
@{} and %{}, &{} are not supported. see "HASH, ARRAY, CODE ACCESS" instead.
@{}
%{}
&{}
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}
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.
Copyright (C) Masahiro Honma.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Masahiro Honma <hiratara@cpan.org>
To install Test::AutoMock, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::AutoMock
CPAN shell
perl -MCPAN -e shell install Test::AutoMock
For more information on module installation, please visit the detailed CPAN module installation guide.