Skip to content

Instantly share code, notes, and snippets.

@yusukebe
Created May 10, 2014 02:51
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 yusukebe/4023b56401371808f43b to your computer and use it in GitHub Desktop.
Save yusukebe/4023b56401371808f43b to your computer and use it in GitHub Desktop.
Shortcut method with Mouse::Role for Data::Validator
package Role;
use 5.10.0;
use Mouse::Role;
use Data::Validator;
use DB;
sub args {
{
package DB;
() = caller(1);
}
my @args = @DB::args;
my $class = shift @args;
my $rule = Data::Validator->new(@_)->with('Method');
my $args = $rule->validate(@args);
return ($class, $args);
}
1;
__END__
=head1 SYNOPSIS
package SomeClass;
use 5.10.0;
use Mouse;
with qw/Role/;
sub get {
my ($self, $args) = args(
foo => { isa => 'Str', default => 'bar' }
);
say $args->{foo};
}
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment