X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouseX%2FTypes%2FTypeDecorator.pm;fp=lib%2FMouseX%2FTypes%2FTypeDecorator.pm;h=244f88c463c9e468cb9cb42cec95556f75fdaadb;hb=6da1e93610cfec750bed324e9bea74965e37f96e;hp=0000000000000000000000000000000000000000;hpb=eec1bb49cc5fcd39b8923dfc56ca568359122784;p=gitmo%2FMouse.git diff --git a/lib/MouseX/Types/TypeDecorator.pm b/lib/MouseX/Types/TypeDecorator.pm new file mode 100644 index 0000000..244f88c --- /dev/null +++ b/lib/MouseX/Types/TypeDecorator.pm @@ -0,0 +1,41 @@ +package MouseX::Types::TypeDecorator; + +use strict; +use warnings; + +use Mouse::Util 'blessed'; + +use overload( + '""' => sub { ${ $_[0] } }, + '|' => sub { + + ## It's kind of ugly that we need to know about Union Types, but this + ## is needed for syntax compatibility. Maybe someday we'll all just do + ## Or[Str,Str,Int] + + my @tc = grep {blessed $_} @_; + use Data::Dumper; + my $ret; + if (ref($_[0])) { + $ret = ${ $_[0] }; + } else { + $ret = $_[0]; + } + $ret .= '|'; + if (ref($_[1])) { + $ret .= ${ $_[1] }; + } else { + $ret .= $_[1]; + } + $ret; + }, + fallback => 1, + +); + +sub new { + my $type = $_[1]; + bless \$type, $_[0]; +} + +1;