1. Konstantin Baierer
  2. p5-moosex-semantic

Commits

Konstantin Baierer  committed 18016f3

basic support for MooseX::Types type constraints (i.e. typedecorators)

  • Participants
  • Parent commits 4ccc0b6
  • Branches default

Comments (0)

Files changed (2)

File lib/MooseX/Semantic/Types.pm

View file
  • Ignore whitespace
 );
 
 coerce( ArrayOfTrineResources,
+    # from Str, via { [ TrineResource->coerce( $_ ) ] },
     from TrineResource, via { [ $_ ] },
     from ArrayRef, via { my $u = $_; [map {TrineResource->coerce($_)} @$u] },
     from Value, via { [ TrineResource->coerce( $_ ) ] },

File lib/MooseX/Semantic/Util/TypeConstraintWalker.pm

View file
  • Ignore whitespace
 use Try::Tiny;
 use Data::Dumper;
 use MooseX::Semantic::Types qw(UriStr);
+use Data::Printer;
 use feature qw(switch);
 use Log::Log4perl;
 my $logger = Log::Log4perl->get_logger(__PACKAGE__);
 
+#TODO proper support for MooseX::Types!!!
+
 sub _find_parent_type {
     my ($self, $attr_or_type_constraint, $needle, %opts) = @_;
     return unless $attr_or_type_constraint;
         # my $attr = $self->meta->get_attribute($attr_name);
         next unless ($attr->does('MooseX::Semantic::Meta::Attribute::Trait'));
         my $attr_type = $attr->type_constraint;
+        if (ref $attr_type eq 'MooseX::Types::TypeDecorator') {
+            warn Dumper $attr_name;
+            warn Dumper ref $attr_type;
+            $attr_type = $attr_type->__type_constraint->parent;
+            p $attr_type;
+        }
+        else {
+            p $attr_name;
+            p $attr_type;
+        }
 
         my $stash = {};
         $stash->{uris}  = [$attr->uri] if $attr->has_uri;
             $callback_name = 'literal';
         }
         elsif ($self->_find_parent_type($attr->type_constraint, 'ArrayRef')) {
-            if ( ! $attr_type->can('type_parameter')
-                || $attr_type->type_parameter eq 'Str'
-                || $self->_find_parent_type( $attr_type->type_parameter, 'Num' )
-                || $self->_find_parent_type( $attr_type->type_parameter, 'Bool' ))
-            {
+            if ( ! $attr_type->can('type_parameter')) {
+                warn Dumper "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
+                # warn Dumper ref $attr_type;
+                p $attr_type;
                 $callback_name = 'literal_in_array';
             }
             elsif ( $self->_find_parent_type( $attr_type->type_parameter, 'Object' ) 
-                || $self->_find_parent_type( $attr_type->type_parameter, 'ClassName' ) ) {
+            or      $self->_find_parent_type( $attr_type->type_parameter, 'ClassName' ) ) 
+            {
                 $callback_name = 'resource_in_array';
             }
+            elsif ( $attr_type->type_parameter eq 'Str'
+            or      $self->_find_parent_type( $attr_type->type_parameter, 'Num' )
+            or      $self->_find_parent_type( $attr_type->type_parameter, 'Bool' ))
+            {
+                $callback_name = 'literal_in_array';
+            }
         }
         else {
             # warn Dumper $attr_type->has_parent;