-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow parameterized types to customize their messages
The same arguments that are passed to the where block are also passed to the message block to allow the error message to be customized.
- Loading branch information
Brian Phillips
committed
Aug 2, 2011
1 parent
3782156
commit fd19723
Showing
2 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
use MooseX::Types -declare=>[qw( SizedArray )]; | ||
use MooseX::Types::Parameterizable qw(Parameterizable); | ||
use MooseX::Types::Moose qw( Int ArrayRef ); | ||
|
||
ok subtype( | ||
SizedArray, | ||
as Parameterizable[ArrayRef,Int], | ||
where { | ||
my ($value, $max) = @_; | ||
@$value > $max | ||
}, | ||
message { | ||
my($value, $max) = @_; | ||
return sprintf('%d > %d', scalar(@$value), $max); | ||
} | ||
), 'Created parameterized type'; | ||
|
||
is SizedArray([3])->get_message([1..4]), q{4 > 3}, 'custom message'; | ||
|
||
done_testing; |