Skip to content

Instantly share code, notes, and snippets.

@stevan
Created January 4, 2010 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevan/268717 to your computer and use it in GitHub Desktop.
Save stevan/268717 to your computer and use it in GitHub Desktop.
use Moose::Util::TypeConstraints;
use MooseX::Params::Validate;
subtype 'Filename' => as 'Str' => where { -x $_ };
sub foo {
my ($name) = pos_validated_list( \@_, { isa => 'Filename' } );
print "Houston, we have a filename: $name \n";
}
my $perl = `which perl`; chomp $perl;
foo($perl);
foo('no_such_file');
stevan% perl ovid.pl
Houston, we have a filename: /usr/local/perls/bin/perl
Parameter #1 ("no_such_file") to main::foo did not pass
the 'checking type constraint for Filename' callback ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment