Matching simply

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 ) {

Increasing Perl’s Visibility, Redux

Quite a while ago, I blogged about how Perl projects should have websites to increase not only their visibility, but the visibility of Perl as a whole.

Perl has had the CPAN and awesome websites like MetaCPAN and its predecessor for a long time, so unlike how things happen in other programming language ecosystems, many Perl projects have felt no need to start their own websites for documentation, package downloads, and community — all these things were already provided.

However, I do feel that this centralization keeps Perl content on the Internet very isolated and makes Perl less visible than other programming languages.

Experiments in Overloading

Let's play with overloading a little.

A simple class:

  package Local::Overloaded {
    use Moo;
    has number => ( is => 'ro' );
    use overload '0+' => sub {
      my $self = shift;
      return $self->number;

And let's test it:

  use Test2::V0;
  my $obj = Local::Overloaded->new( number => 42 );
  is( 0+$obj, 42 );

This test fails.


Introducing Exporter::Almighty

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;

Using Type::Params Effectively

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.

About Toby Inkster

user-pic I'm tobyink on CPAN, IRC and PerlMonks.