From: Stevan Little Date: Mon, 13 Mar 2006 14:56:26 +0000 (+0000) Subject: fixing the UI X-Git-Tag: 0_05~105 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=29db16a9aa7532a01390dddb9fc5dee43429a12a;p=gitmo%2FMoose.git fixing the UI --- diff --git a/lib/Moose.pm b/lib/Moose.pm index 48dddc8..40f4650 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -45,7 +45,18 @@ sub import { $meta->alias_method('extends' => subname 'Moose::extends' => sub { $meta->superclasses(@_) }); # handle attributes - $meta->alias_method('has' => subname 'Moose::has' => sub { $meta->add_attribute(@_) }); + $meta->alias_method('has' => subname 'Moose::has' => sub { + my ($name, %options) = @_; + if (exists $options{is}) { + $options{type_constraint} = $options{is}; + } + elsif (exists $options{isa}) { + $options{type_constraint} = Moose::Util::TypeConstraints::subtype( + Object => Moose::Util::TypeConstraints::where { $_->isa($options{isa}) } + ); + } + $meta->add_attribute($name, %options) + }); # handle method modifers $meta->alias_method('before' => subname 'Moose::before' => sub { diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index f79b99b..464aa66 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -32,7 +32,8 @@ Moose::Meta::Attribute->meta->add_attribute( Moose::Meta::Attribute->meta->add_before_method_modifier('new' => sub { my (undef, undef, %options) = @_; (reftype($options{type_constraint}) && reftype($options{type_constraint}) eq 'CODE') - || confess "Type cosntraint parameter must be a code-ref"; + || confess "Type cosntraint parameter must be a code-ref, not " . $options{type_constraint} + if exists $options{type_constraint}; }); sub generate_accessor_method { diff --git a/t/001_basic.t b/t/001_basic.t index 21ec499..f4fcd52 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -15,15 +15,15 @@ BEGIN { use strict; use warnings; use Moose; - + has 'x' => ( - reader => 'x', - type_constraint => Int(), + is => Int(), + reader => 'x', ); - + has 'y' => ( - accessor => 'y', - type_constraint => Int(), + is => Int(), + accessor => 'y', ); sub clear { @@ -39,7 +39,7 @@ BEGIN { extends 'Point'; - has 'z' => (type_constraint => Int()); + has 'z' => (is => Int()); after 'clear' => sub { my $self = shift; diff --git a/t/002_basic.t b/t/002_basic.t index 2b376a6..ad2a59d 100644 --- a/t/002_basic.t +++ b/t/002_basic.t @@ -17,9 +17,9 @@ BEGIN { use Moose; has 'balance' => ( - accessor => 'balance', - default => 0, - type_constraint => Int(), + is => Int(), + accessor => 'balance', + default => 0, ); sub deposit { @@ -43,8 +43,8 @@ BEGIN { extends 'BankAccount'; has 'overdraft_account' => ( - accessor => 'overdraft_account', - type_constraint => subtype Object => where { $_->isa('BankAccount') }, + isa => 'BankAccount', + accessor => 'overdraft_account', ); before 'withdraw' => sub { diff --git a/t/003_basic.t b/t/003_basic.t index df9c72c..e22eede 100644 --- a/t/003_basic.t +++ b/t/003_basic.t @@ -19,22 +19,22 @@ BEGIN { use Moose; has 'parent' => ( - predicate => 'has_parent', - accessor => 'parent', - weak_ref => 1, - type_constraint => subtype Object => where { $_->isa('BinaryTree') }, + isa => 'BinaryTree', + predicate => 'has_parent', + accessor => 'parent', + weak_ref => 1, ); has 'left' => ( - predicate => 'has_left', - accessor => 'left', - type_constraint => subtype Object => where { $_->isa('BinaryTree') }, + isa => 'BinaryTree', + predicate => 'has_left', + accessor => 'left', ); has 'right' => ( - predicate => 'has_right', - accessor => 'right', - type_constraint => subtype Object => where { $_->isa('BinaryTree') }, + isa => 'BinaryTree', + predicate => 'has_right', + accessor => 'right', ); before 'right', 'left' => sub {