X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose.pm;h=6f972bc0f5976886331e87014b2f2267a4ae5332;hb=7415b2cb4557d036bd6be89954fc4682cdedc5d5;hp=f279bb8172a0ed322b44d699a784af68bc897838;hpb=7f18097c5938a5dfc6cdb19990b6e950f003c9d8;p=gitmo%2FMoose.git diff --git a/lib/Moose.pm b/lib/Moose.pm index f279bb8..6f972bc 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -1,6 +1,4 @@ -use lib '/Users/stevan/Projects/CPAN/Class-MOP/Class-MOP/lib'; - package Moose; use strict; @@ -17,14 +15,11 @@ use UNIVERSAL::require; use Class::MOP; use Moose::Meta::Class; -use Moose::Meta::SafeMixin; use Moose::Meta::Attribute; +use Moose::Meta::TypeConstraint; use Moose::Object; -use Moose::Util::TypeConstraints ':no_export'; - -# bootstrap the mixin module -Moose::Meta::SafeMixin::mixin(Moose::Meta::Class->meta, 'Moose::Meta::SafeMixin'); +use Moose::Util::TypeConstraints; sub import { shift; @@ -34,6 +29,11 @@ sub import { return if $pkg eq 'main'; Moose::Util::TypeConstraints->import($pkg); + + # make a subtype for each Moose class + subtype $pkg + => as Object + => where { $_->isa($pkg) }; my $meta; if ($pkg->can('meta')) { @@ -61,10 +61,7 @@ sub import { $meta->alias_method('extends' => subname 'Moose::extends' => sub { $_->require for @_; $meta->superclasses(@_) - }); - - # handle mixins - $meta->alias_method('with' => subname 'Moose::with' => sub { $meta->mixin($_[0]) }); + }); # handle attributes $meta->alias_method('has' => subname 'Moose::has' => sub { @@ -78,13 +75,26 @@ sub import { } } if (exists $options{isa}) { - if (reftype($options{isa}) && reftype($options{isa}) eq 'CODE') { - $options{type_constraint} = $options{isa}; + # allow for anon-subtypes here ... + if (reftype($options{isa}) && reftype($options{isa}) eq 'CODE') { + $options{type_constraint} = Moose::Meta::TypeConstraint->new( + name => '__ANON__', + constraint_code => $options{isa} + ); } else { - $options{type_constraint} = Moose::Util::TypeConstraints::subtype( - Object => Moose::Util::TypeConstraints::where { $_->isa($options{isa}) } - ); + # 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::Meta::TypeConstraint->new( + name => '__ANON__', + constraint_code => subtype Object => where { $_->isa($constraint) } + ); + } + $options{type_constraint} = $constraint; } } $meta->add_attribute($name, %options) @@ -129,8 +139,8 @@ Moose - Moose, it's the new Camel package Point; use Moose; - has 'x' => (isa => Int(), is => 'rw'); - has 'y' => (isa => Int(), is => 'rw'); + has 'x' => (isa => 'Int', is => 'rw'); + has 'y' => (isa => 'Int', is => 'rw'); sub clear { my $self = shift; @@ -143,7 +153,7 @@ Moose - Moose, it's the new Camel extends 'Point'; - has 'z' => (isa => Int()); + has 'z' => (isa => 'Int'); after 'clear' => sub { my $self = shift; @@ -214,6 +224,17 @@ this module would not be possible (and it wouldn't have a name). =item The basis of the TypeContraints module was Rob Kinyon's idea originally, I just ran with it. +=item Much love to mst & chansen and the whole #moose poose for all the +ideas/feature-requests/encouragement + +=back + +=head1 SEE ALSO + +=over 4 + +=item L + =back =head1 BUGS