]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/commitdiff
Remove the user_constraint feature from the autocoercion code
authorVincent Pit <vince@profvince.com>
Tue, 6 Aug 2013 15:53:47 +0000 (12:53 -0300)
committerVincent Pit <vince@profvince.com>
Tue, 6 Aug 2013 16:07:52 +0000 (13:07 -0300)
We don't need it and it makes the code harder to look at than necessary.

lib/LaTeX/TikZ/Meta/TypeConstraint/Autocoerce.pm

index 00fbbf4a547ac485aa787a15defb9fdc92d651d2..0356cb0a29a13da9dbf80ae2415a5bba93194512 100644 (file)
@@ -140,20 +140,9 @@ has 'target' => (
 my $target_tc = __PACKAGE__->meta->find_attribute_by_name('target')
                                  ->type_constraint;
 
 my $target_tc = __PACKAGE__->meta->find_attribute_by_name('target')
                                  ->type_constraint;
 
-=head2 C<user_constraint>
-
-An optional user defined code reference which predates checking the target for validity.
-
-=cut
-
-has 'user_constraint' => (
- is  => 'ro',
- isa => 'Maybe[CodeRef]',
-);
-
 =head1 METHODS
 
 =head1 METHODS
 
-=head2 C<< new name => $name, mapper => $mapper, target => $target, [ user_constraint => sub { ... } ] >>
+=head2 C<< new name => $name, mapper => $mapper, target => $target >>
 
 Constructs a type constraint object that will attempt to autocoerce objects that are not valid according to C<$target> by loading the class returned by C<$mapper>.
 
 
 Constructs a type constraint object that will attempt to autocoerce objects that are not valid according to C<$target> by loading the class returned by C<$mapper>.
 
@@ -179,26 +168,18 @@ around 'new' => sub {
   $args{coercion} = Moose::Meta::TypeCoercion->new;
  }
 
   $args{coercion} = Moose::Meta::TypeCoercion->new;
  }
 
- my $tc;
  $args{constraint} = Sub::Name::subname('_constraint' => sub {
   my ($thing) = @_;
 
   # Remember that when ->check is called inside coerce, a return value of 0
   # means that coercion should take place, while 1 signifies that the value is
  $args{constraint} = Sub::Name::subname('_constraint' => sub {
   my ($thing) = @_;
 
   # Remember that when ->check is called inside coerce, a return value of 0
   # means that coercion should take place, while 1 signifies that the value is
-  # already OK.
-
-  # First, try a possible user defined constraint
-  my $user = $tc->user_constraint;
-  if (defined $user) {
-   my $ok = $user->($thing);
-   return 1 if $ok;
-  }
+  # already OK. Thus we should return true if and only if $thing passes the
+  # target type constraint.
 
 
-  # Then, it's valid if and only if it passes the target type constraint
-  return $tc->target->check($thing);
+  return $target->check($thing);
  });
 
  });
 
$tc = $class->$orig(%args);
return $class->$orig(%args);
 };
 
 =head2 C<coerce $thing>
 };
 
 =head2 C<coerce $thing>