given/when and lexical $_ ...

... or happy debugging!

TL;DR Upd: Use for instead of given, as Aristotle suggests.

Here are some code snippets to show what's wrong with given/when.

use 5.010;
use strict;
use List::MoreUtils qw/any/;

given ('test') {
    when ('test') {
        say "any" if any {$_ == 2} (2, 3);

The above code prints nothing. Ok, let's change any to grep to see if it works: MooseX::Declare -> Moose

Our current project at my job is based solely on rather sophisticated object model, we've chosen MooseX::Declare as one of our main helpers. We are very happy with compiletime argument checks, I guess it saves us a lot of debugging time.

The problem was solved by implementing a tool…