use Scalar::Util 'weaken', 'reftype';
use Carp 'confess';
-use Moose::Util::TypeConstraints ':no_export';
-
our $VERSION = '0.02';
use base 'Class::MOP::Attribute';
-Moose::Meta::Attribute->meta->add_attribute(
- Class::MOP::Attribute->new('coerce' => (
- reader => 'coerce',
- predicate => {
- 'has_coercion' => sub { $_[0]->coerce() ? 1 : 0 }
- }
- ))
-);
-
-Moose::Meta::Attribute->meta->add_attribute(
- Class::MOP::Attribute->new('weak_ref' => (
- reader => 'weak_ref',
- predicate => {
- 'has_weak_ref' => sub { $_[0]->weak_ref() ? 1 : 0 }
- }
- ))
-);
+__PACKAGE__->meta->add_attribute('coerce' => (
+ reader => 'coerce',
+ predicate => { 'has_coercion' => sub { $_[0]->coerce() ? 1 : 0 } }
+));
+
+__PACKAGE__->meta->add_attribute('weak_ref' => (
+ reader => 'weak_ref',
+ predicate => { 'has_weak_ref' => sub { $_[0]->weak_ref() ? 1 : 0 } }
+));
-Moose::Meta::Attribute->meta->add_attribute(
- Class::MOP::Attribute->new('type_constraint' => (
- reader => 'type_constraint',
- predicate => 'has_type_constraint',
- ))
-);
+__PACKAGE__->meta->add_attribute('type_constraint' => (
+ reader => 'type_constraint',
+ predicate => 'has_type_constraint',
+));
-Moose::Meta::Attribute->meta->add_before_method_modifier('new' => sub {
+__PACKAGE__->meta->add_before_method_modifier('new' => sub {
my (undef, undef, %options) = @_;
if (exists $options{coerce} && $options{coerce}) {
(exists $options{type_constraint})
our $VERSION = '0.01';
-my %TYPE_CONSTRAINT_REGISTRY;
-
__PACKAGE__->meta->add_attribute('name' => (reader => 'name' ));
__PACKAGE__->meta->add_attribute('parent' => (reader => 'parent' ));
__PACKAGE__->meta->add_attribute('constraint' => (reader => 'constraint'));
':attribute_metaclass' => 'Moose::Meta::Attribute'
);
-use Carp 'confess';
-
our $VERSION = '0.02';
sub new {
- my $class = shift;
- my %params = @_;
+ my ($class, %params) = @_;
my $self = $class->meta->new_object(%params);
$self->BUILDALL(%params);
return $self;
{
my %TYPES;
- sub find_type_constraint {
- my $type_name = shift;
- $TYPES{$type_name};
- }
+ sub find_type_constraint { $TYPES{$_[0]} }
- sub register_type_constraint {
+ sub create_type_constraint {
my ($name, $parent, $constraint) = @_;
(not exists $TYPES{$name})
- || confess "The type constraint '$name' has already been registered";
+ || confess "The type constraint '$name' has already been created";
$parent = find_type_constraint($parent) if defined $parent;
$TYPES{$name} = Moose::Meta::TypeConstraint->new(
name => $name,
sub type ($$) {
my ($name, $check) = @_;
- register_type_constraint($name, undef, $check);
+ create_type_constraint($name, undef, $check);
}
sub subtype ($$;$) {
if (scalar @_ == 3) {
my ($name, $parent, $check) = @_;
- register_type_constraint($name, $parent, $check);
+ create_type_constraint($name, $parent, $check);
}
else {
my ($parent, $check) = @_;
=item B<find_type_constraint ($type_name)>
-=item B<register_type_constraint ($type_name, $type_constraint)>
+=item B<create_type_constraint ($type_name, $type_constraint)>
=item B<find_type_coercion>