Created
May 10, 2014 02:51
-
-
Save yusukebe/4023b56401371808f43b to your computer and use it in GitHub Desktop.
Shortcut method with Mouse::Role for Data::Validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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