{
$Test::Mocha::Mock::VERSION
=
'0.13'
;
}
extract_method_name
get_attribute_value
has_caller_package
)
;
our
$AUTOLOAD
;
has
'class'
=> (
isa
=> Str,
reader
=>
'ref'
,
default
=> __PACKAGE__,
);
has
'calls'
=> (
isa
=> ArrayRef[InstanceOf[Invocation]],
is
=>
'bare'
,
default
=>
sub
{ [] }
);
has
'stubs'
=> (
isa
=> Map[ Str, ArrayRef[InstanceOf[Stub]] ],
is
=>
'bare'
,
default
=>
sub
{ {} }
);
sub
AUTOLOAD {
my
$self
=
shift
;
my
$method_name
= extract_method_name(
$AUTOLOAD
);
my
@invalid_args
=
grep
{ Matcher->check(
$_
) }
@_
;
croak
'Mock methods may not be called with '
.
'type constraint arguments: '
.
join
(
', '
,
@invalid_args
)
unless
@invalid_args
== 0;
my
$method_call
= Invocation->new(
name
=>
$method_name
,
args
=> \
@_
,
);
my
$calls
= get_attribute_value(
$self
,
'calls'
);
my
$stubs
= get_attribute_value(
$self
,
'stubs'
);
push
@$calls
,
$method_call
;
if
(
defined
$stubs
->{
$method_name
}) {
foreach
my
$stub
( @{
$stubs
->{
$method_name
}} ) {
return
$stub
->execute
if
$stub
->satisfied_by(
$method_call
);
}
}
return
;
}
sub
isa {
my
(
$self
,
$package
) =
@_
;
return
if
(
$package
eq
'Type::Tiny'
||
$package
eq
'Moose::Meta::TypeConstraint'
||
has_caller_package(
'UNIVERSAL::ref'
)
);
return
1;
}
sub
does {
return
if
has_caller_package(
'UNIVERSAL::ref'
);
return
1;
}
sub
can {
my
(
$self
,
$method_name
) =
@_
;
return
sub
{
$AUTOLOAD
=
$method_name
;
goto
&AUTOLOAD
;
};
}
__PACKAGE__->meta->make_immutable;
1;