The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Magpie::ArgumentMatcher - Various templates to catch arguments

SYNOPSIS

    use Test::Magpie::ArgumentMatcher qw( anything );
    use Test::Magpie qw( mock verify );

    my $mock = mock;
    $mock->push( button => 'red' );

    verify($mock)->push(anything);

DESCRIPTION

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 undef if the argument does not pass validation.

Custom argument validators

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.

Default argument matchers

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.

METHODS

match @in

Match an argument matcher against @in, and return a list of parameters still to be consumed, or undef on validation.

FUNCTIONS

anything

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.

AUTHOR

Oliver Charles

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Oliver Charles <oliver.g.charles@googlemail.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.