Yeah, I have to agree, my first reaction was based on the examples and
tests, but upon further review of the code I think Dave is right.
You see, in Moose a type constraint acts upon the value in the
attribute and knows nothing of the object that contains it. This is
part of what makes Moose type constraints so useful outside of Moose
as well as inside.
I am not actually sure you need to include types in this, much of what
you are using Moose::Meta::TypeConstraint could easily be written as a
stand along "Dependency" class. Additionally by adding your types to
the global type registry in MooseX::Dependency::Types you are making
them accessible to everyone as proper Moose types, which they really
aren't since they require a specialized set of arguments.
I think you could easily remove the type-system elements of this and
create a nice and useful MooseX:: module that handles the dependencies
between attributes.
I do like the Any[], All[], etc. though, so I think you should keep
that.
- Stevan
On Dec 26, 2010, at 10:17 AM, Dave Rolsky wrote:
On Sun, 26 Dec 2010, Stevan Little wrote:
Looks good, however I think MooseX::Depedency is too general a
name, how about MooseX::Types::Dependent::Types?
I don't think this is what dependent types means.
No, but kinda. Dependent types are a type of type system (hehe) that
are dependent upon runtime values, the example on wikipedia (http://en.wikipedia.org/wiki/Dependent_type
) is kinda nice :
An example is the type of n-tuples of real numbers. This is a
dependent type because the type depends on the value n.
So in (psuedo) Moose land that might be something like:
subtype IntTuple => as_dependent_type { Tuple[ type => 'Int', size
=> $_[0] ] };
Where '$_[0]' is parameterizable for the given type, like so:
has small_tuple => ( ... isa => IntTuple[ 2 ] ... );
has big_tuple => ( ... isa => IntTuple[ 20 ] ... );
This example wouldn't of course help if you wanted access to $self,
but the idea could be expanded upon perhaps to work in this case.
Honestly though, I think this really overcomplicates the type system
and is much more difficult to use and understand then something more
like what Moritz has created here.
Also, I'm not sure this has anything to do with types at all. This
is really about whether a value is _required_.
Maybe MX::Attribute::Dependent or something like that.
-dave
/*============================================================
http://VegGuide.org http://blog.urth.org
Your guide to all that's veg House Absolute(ly Pointless)
============================================================*/