19 Nov 2010 03:14:28 UTC
- Distribution: Test-Magpie
- Module version: 0.04
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (29 / 41 / 0)
- KwaliteeBus factor: 0
- License: perl_5
- Activity24 month
- Download (17.71KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionCYCLES Oliver Charlesand 1 contributors
- Oliver Charles
- COPYRIGHT AND LICENSE
Test::Magpie::ArgumentMatcher - Various templates to catch arguments
use Test::Magpie::ArgumentMatcher qw( anything ); use Test::Magpie qw( mock verify ); my $mock = mock; $mock->push( button => 'red' ); verify($mock)->push(anything);
Argument matchers allow you to be more general in your specification to stubs and verification. An argument matcher is an object that takes all remaining paremeters of an invocation, consumes 1 or more, and returns the remaining arguments back. At verification time, a invocation is verified if all arguments have been consumed by all argument matchers.
An argument matcher may return
undefif the argument does not pass validation.
An argument validator is just a subroutine that is blessed as
Test::Magpie::ArgumentMatcher. You are welcome to subclass this package if you wish to use a different storage system (like a traditional hash-reference), though a single sub routine is normally all you will need.
This module provides a set of common argument matchers, and will probably handle most of your needs. They are all available for import by name.
Match an argument matcher against @in, and return a list of parameters still to be consumed, or undef on validation.
Consumes all remaining arguments (even 0) and returns none. This effectively slurps in any remaining arguments and considers them valid. Note, as this consumes all arguments, you cannot use further argument validators after this one. You are, however, welcome to use them before.
Creates a custom argument matcher for you. This argument matcher is assumed to be the final argument matcher. If this matcher passes (that is, returns a true value), then it is assumed that all remaining arguments have been matched.
Custom matchers are code references. You can use $_ to reference to the first argument, but a custom argument matcher may match more than one argument. It is passed the contents of
@_that have not yet been matched, in essence.
Checks that a single value meets a given Moose type constraint. You may want to consider the use of MooseX::Types here for code clarity.
Does deep comparison on all remaining arguments, and verifies that they meet the specification in
%match. Note that this is for hashes, not hash references!
Compares that all remaining arguments match the set of values in
@values. This allows you to compare objects out of order.
Note: this currently uses real Set::Objects to do the work which means duplicate arguments are ignored. For example
1, 1, 2will match
1, 2, 2. This is probably a bug and I will fix it, but for now I'm mostly waiting for a bug report - sorry!
This software is copyright (c) 2010 by Oliver Charles <email@example.com>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.