NAME
Evo::Spy - A basic spy function-object
VERSION
version 0.0161
SYNOPSIS
use Evo::Base -strict;
use Evo::Spy;
my $spy = Evo::Spy->new(sub { say "hello ", shift });
$spy->('foo');
$spy->code->('bar');
use Data::Dumper;
say Dumper $spy->calls;
METHODS
origin
An original code.
new
Creates a new spy. If no origin will be passed, spy will still record all invocations, but do nothing
code
Returns a code that can be used as a spy. Why to use it if a spy is already a code itself? Because some code can check if passed argument is a code by calling ref $spy
instead of reftype $spy
, and while the spy is an instance of Evo::Spy or it's subclass, that code may not recognize a spy as a subroutine ref.
# Evo::Spy
say ref $spy;
# CODE
say Scalar::Util::reftype $spy;
# always CODE
say ref $spy->code;
say Scalar::Util::reftype $spy->code;
So here is a rule, use the shorter form for spying your own code, because it's a shorter use "code" if you get an exception can not use ... as a subroutine ref..
All variants do the same thing, the only difference is a type recognition
calls
Returns an array ref to information of all invocations of $spy-
()> or $spy-
code()>. Don't rely on implementation and don't use this directly. Use subclasses of Evo::Spy instead which provide methods for that
AUTHOR
alexbyk.com
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by alexbyk.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.