A little over ten years ago, when Perl 5.18 was approaching its release date, I released match::simple. This was mostly in response to the smartmatch operator (~~
) being deprecated, but also a solution to the incredibly arcane rules for how the smartmatch operator operated.
match::simple was intended to be... simpler. The operator looks a little funky because it uses some clever trickery to fake being an infix operator:
use match::simple;
if ( $this |M| $that ) {
...;
}
Consider a simple module like this:
package MyApp::Util::Maths;
use strict;
use warnings;
use constant PI => 3.14159265358979;
use constant EULER => 2.71828182845905;
use base 'Exporter';
our @EXPORT_OK = qw( PI EULER add );
our %EXPORT_TAGS = (
arithmetic => [ qw( add ) ],
numbers => [ qw( PI EULER ) ],
all => \@EXPORT_OK,
);
sub add {
my ( $x, $y ) = @_;
return $x + $y;
}
1;
One of the modules bundled with Type::Tiny is Type::Params, a module that allows you to validate subroutine signatures using type constraints. It's one of the more popular parts of the suite.
This article provides a few hints for using it effectively.