=head1 NAME Test::Mock::Signature - base class for mock modules. =head1 SYNOPSIS Create module for mocking CGI: package Your::Mock::Module; use strict; use warnings; require Test::Mock::Signature; our @ISA = qw(Test::Mock::Signature); our $CLASS = 'CGI'; sub init { my $mock = shift; $mock->method('new')->callback( sub { my $class = shift; return bless({}, $class); } ); } Use it in tests: use Test::More plan => 1; use Your::Mock::Module qw( any ); use CGI; my $mock = Your::Mock::Module->new; $mock->method('param' => any)->callback( sub { 42 } ); my $request = CGI->new; ok($request->param('something'), 42, 'mocked'); =head1 DESCRIPTION This module is a base class for your mock module with ability to set callbacks for defined signature of your method. =head1 METHODS =head2 import( any ) This method imports magic constant C from class L and does some magic behind the scene. Also it takes real class name from your C variable. =head2 new() Default constructor. To simplify inheritance there are another method defined C which will be called from constructor. =head2 init() Empty method invoked from constructor C. Can be overrided to define default mocked methods e.g.: constructors. =head2 method($method_name, [ @params ]) : L This method does the actual mocking of methods e.g.: my $mock = Your::Mock::Module->new; my $cgi = new CGI; $mock->method(param => 'get_param')->callback( sub { return 42; } ); print $cgi->param('get_param'); # 42 print $cgi->param('ANYTHING_ELSE'); # will give original CGI::param behavior C<@params> can contain object C exported by the mock module if needed for detailed reference please look to: L. Returns object of L class. =head2 clear($method_name, [ @params ]) Clear mocking behavior from method. Takes C<$method_name> as a first parameter. Prototype is optional. If you put only method name it remove all mocks from this method. If you put prototype parameters it finds this signature and delete it. e.g.: $mock->clear(param => 'get_param'); # delete exact signature $mock->clear('param'); # delete all mocked signatures from method "param" =head2 dispatcher($method_name) : L This method returns dispatcher object for the given C<$method_name>. Currently it's exposed as public just in case. Used for internal use and don't have any real user examples. =head1 AUTHOR cono Econo@cpan.orgE =head1 COPYRIGHT Copyright 2014 - cono =head1 LICENSE Artistic v2.0 =head1 SEE ALSO L