Permalink
Browse files

TypeConstraint::Utils,.. now with find_or_create_type_constraint good…

…ness
  • Loading branch information...
1 parent b17a303 commit d9b400059075f0cdffc909861da391aff5f7db66 Stevan Little committed Sep 16, 2007
View
65 PLANS
@@ -9,30 +9,6 @@ This will make it much easier to generate TCs on their own, without
having to use the sugar layer. This should also clean up their APIs
as well, which will make it easier to subclass them.
-- create an official TC registry API
-
-Right now the registration of the TC is a by-product of creation in the sugar
-layer, this is bad and make extension of TCs difficult. I am not sure if this
-registry API should exist as part of Moose::Util::TypeConstraints, or of we
-should create a complete registry object itself.
-
-This registry should be a singleton, but M::U::TC should enforce that lifecycle
-choice so that you can use your own registry if you really want too.
-
-I mean parent of the registry. So that I can create my own registry
-object for a given class, and any retrieval of a type constraint from
-this object would automatically search parent registries as well.
-
-- refactor the various TC internals to make it more subclassing friendly
-
-This also includes the coercion stuff as well. This should give you what you
-need to make your object/class bound stuff.
-
-- move the container TCs from MooseX::AttributeHelpers into Moose core
-
-These have proven so useful for me in the latest $work project that I think
-they should really be core.
-
- allow a switch of some kind to optionally turn TC checking off at runtime
The type checks can get expensive and some people have suggested that allowing
@@ -87,6 +63,47 @@ subtype Foo => as Bar => where { ... } => in __PACKAGE__ ;
my $Foo = subtype Bar => where { ... };
+# ----------
+
+[17:10] <autarch> stevan: it should do it if I pass coerce => 1 as part of the attribute definition
+[17:12] <stevan> autarch: what I am not 100% sure of is how to tell it to deep coerce and when to not
+[17:13] <stevan> cause a basic coerce is from A to B
+[17:13] <autarch> hmm
+[17:13] <stevan> which is valid for collection types too
+[17:13] <stevan> deep coercion is what you are asking for
+[17:13] <autarch> yeah
+[17:13] <stevan> so perhaps we add deep_coerce => 1
+[17:13] <stevan> which will do it
+[17:13] <autarch> that's fine for me
+[17:13] <stevan> k
+
+-----------------------------------------------------------
+- TC stuff DONE
+-----------------------------------------------------------
+
+- create an official TC registry API (DONE)
+
+Right now the registration of the TC is a by-product of creation in the sugar
+layer, this is bad and make extension of TCs difficult. I am not sure if this
+registry API should exist as part of Moose::Util::TypeConstraints, or of we
+should create a complete registry object itself.
+
+This registry should be a singleton, but M::U::TC should enforce that lifecycle
+choice so that you can use your own registry if you really want too.
+
+I mean parent of the registry. So that I can create my own registry
+object for a given class, and any retrieval of a type constraint from
+this object would automatically search parent registries as well.
+
+- refactor the various TC internals to make it more subclassing friendly (DONE)
+
+This also includes the coercion stuff as well. This should give you what you
+need to make your object/class bound stuff.
+
+- move the container TCs from MooseX::AttributeHelpers into Moose core (DONE)
+
+These have proven so useful for me in the latest $work project that I think
+they should really be core.
-----------------------------------------------------------
-- Roles refactor
View
36 TODO
@@ -1,8 +1,6 @@
-------------------------------------------------------------------------------
BUGS
-------------------------------------------------------------------------------
-
-mst: if I do "subtype 'Foo' => as 'Bar';" I get an empty condition and it dies
-------------------------------------------------------------------------------
TODO
@@ -50,26 +48,6 @@ over there.. in that other object
(... probably be a custom metaclass)
-- compile time extends
-
-[00:39] sri but maybe a better syntax for compile time extends
-[00:39] stevan I have been pondering that actually
-[00:39] sri use Moose extends => Foo::Bar
-[00:40] stevan I think now that we have the Sub::Exporter stuff
- in, that kinda thing should be pretty easy
-
-nothingmuch notes that all the constructs should be supported in the entirety of the use clause:
-
- use Moose (
- has => foo (
- ....
- ),
- );
-
-and that if this usage style is used nothing is exported to the namespace.
-
-- default should dclone()
-
- subtype $anon_subtype => where { ... }
[22:56] stevan sub mst_doesnt_like_to_type { (shift)->meta->attr->type_contstraint }
@@ -100,20 +78,6 @@ and that if this usage style is used nothing is exported to the namespace.
[23:01] mst right
[23:01] stevan ok
-- method keyword
-
-[23:37] mst more seriously, I'd still like a "method" keyword or something
-[23:37] mst method 'foo' => sub { ... };
-[23:38] stevan what would it do more than sub foo { ... }?
-[23:39] stevan I would like multimethods actually
-[23:39] mst almost exactly nothing, to begin with
-[23:39] stevan but thats just cause I love CLOS and am reading a book on Dylan now
-[23:40] stevan keyword squating :)
-[23:40] mst but if we need to hook stuff later it's bloody handy to already have people writing it that way
-[23:40] mst right
-...
-[23:49] mst oh, also: method 'has' => sub { ... } could squelch the redefine warning
-
- local coerce
[13:16] mst stevan: slight problem with coerce
@@ -135,27 +135,13 @@ sub _process_options {
$options->{type_constraint} = $options->{isa};
}
else {
-
- if ($options->{isa} =~ /\|/) {
- my @type_constraints = split /\s*\|\s*/ => $options->{isa};
- $options->{type_constraint} = Moose::Util::TypeConstraints::create_type_constraint_union(
- @type_constraints
- );
- }
- else {
- # otherwise assume it is a constraint
- my $constraint = Moose::Util::TypeConstraints::find_type_constraint($options->{isa});
- # if the constraing it not found ....
- unless (defined $constraint) {
- # assume it is a foreign class, and make
- # an anon constraint for it
- $constraint = Moose::Util::TypeConstraints::subtype(
- 'Object',
- Moose::Util::TypeConstraints::where { $_->isa($options->{isa}) }
- );
- }
- $options->{type_constraint} = $constraint;
- }
+ $options->{type_constraint} = Moose::Util::TypeConstraints::find_or_create_type_constraint(
+ $options->{isa},
+ {
+ parent => Moose::Util::TypeConstraints::find_type_constraint('Object'),
+ constraint => sub { $_[0]->isa($options->{isa}) }
+ }
+ );
}
}
elsif (exists $options->{does}) {
@@ -164,18 +150,13 @@ sub _process_options {
$options->{type_constraint} = $options->{isa};
}
else {
- # otherwise assume it is a constraint
- my $constraint = Moose::Util::TypeConstraints::find_type_constraint($options->{does});
- # if the constraing it not found ....
- unless (defined $constraint) {
- # assume it is a foreign class, and make
- # an anon constraint for it
- $constraint = Moose::Util::TypeConstraints::subtype(
- 'Role',
- Moose::Util::TypeConstraints::where { $_->does($options->{does}) }
- );
- }
- $options->{type_constraint} = $constraint;
+ $options->{type_constraint} = Moose::Util::TypeConstraints::find_or_create_type_constraint(
+ $options->{does},
+ {
+ parent => Moose::Util::TypeConstraints::find_type_constraint('Role'),
+ constraint => sub { $_[0]->does($options->{does}) }
+ }
+ );
}
}
Oops, something went wrong.

0 comments on commit d9b4000

Please sign in to comment.