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' );



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.


match @in

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.


Oliver Charles


This software is copyright (c) 2010 by Oliver Charles <>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.