use Scalar::Util directly
[gitmo/Mouse.git] / lib / MouseX / Types / TypeDecorator.pm
1 package MouseX::Types::TypeDecorator;
2
3 use strict;
4 use warnings;
5
6 use Scalar::Util 'blessed';
7
8 use overload(
9     '""' => sub { ${ $_[0] } },
10     '|' => sub {
11         
12         ## It's kind of ugly that we need to know about Union Types, but this
13         ## is needed for syntax compatibility.  Maybe someday we'll all just do
14         ## Or[Str,Str,Int]
15         
16         my @tc = grep {blessed $_} @_;
17         use Data::Dumper;
18         my $ret;
19         if (ref($_[0])) {
20             $ret = ${ $_[0] };
21         } else {
22             $ret = $_[0];
23         }
24         $ret .= '|';
25         if (ref($_[1])) {
26             $ret .= ${ $_[1] };
27         } else {
28             $ret .= $_[1];
29         }
30         $ret;
31     },
32     fallback => 1,
33     
34 );
35
36 sub new {
37     my $type = $_[1];
38     bless \$type, $_[0];
39 }
40
41 1;