Revision history for Perl extension Moose
0.15
+ ++ NOTE ++
+ This version of Moose *must* have Class::MOP 0.36 in order
+ to work correctly. A number of small internal tweaks have
+ been made in order to be compatible with that release.
* Moose::Util::TypeConstraints
- added &unimport so that you can clean out
- fixed minor issue which occasionally
comes up during global destruction
(thanks omega)
-
+ - moved Moose::Meta::Method::Overriden into
+ its own file.
+
+ * Moose::Meta::Role
+ - moved Moose::Meta::Role::Method into
+ its own file.
+
* Moose::Meta::Attribute
- changed how we do type checks so that
we reduce the overall cost, but still
retain correctness.
+ *** API CHANGE ***
+ - moved accessor generation methods to
+ Moose::Meta::Method::Accessor to
+ conform to the API changes from
+ Class::MOP 0.36
* Moose::Meta::TypeConstraint
- changed how constraints are compiled
so that we do less recursion and more
iteration. This makes the type check
faster :)
+ - moved Moose::Meta::TypeConstraint::Union
+ into its own file
+
+ * Moose::Meta::Method::Accessor
+ - created this from methods formerly found in
+ Moose::Meta::Attribute
+
+ * Moose::Meta::Role::Method
+ - moved this from Moose::Meta::Role
+
+ * Moose::Meta::Method::Overriden
+ - moved this from Moose::Meta::Class
+
+ * Moose::Meta::TypeConstraint::Union
+ - moved this from Moose::Meta::TypeConstraint
0.14 Mon. Oct. 9, 2006
## Slot management
-#sub set_value {
-# my ($self, $instance, $value) = @_;
-#}
-#
-#sub get_value {
-# my ($self, $instance) = @_;
-#}
-#
-#sub has_value {
-# my ($self, $instance) = @_;
-#}
-#
-#sub clear_value {
-# my ($self, $instance) = @_;
-#}
+sub set_value {
+ my ($self, $instance, $value) = @_;
+
+ my $attr_name = $self->name;
+
+ if ($self->is_required) {
+ defined($value)
+ || confess "Attribute ($attr_name) is required, so cannot be set to undef";
+ }
+
+ if ($self->has_type_constraint) {
+
+ my $type_constraint = $self->type_constraint;
+
+ if ($self->should_coerce) {
+ $value = $type_constraint->coerce($value);
+ }
+ defined($type_constraint->_compiled_type_constraint->($value))
+ || confess "Attribute ($attr_name) does not pass the type constraint ("
+ . $type_constraint->name . ") with " . (defined($value) ? ("'" . $value . "'") : "undef")
+ if defined($value);
+ }
+
+ my $meta_instance = Class::MOP::Class->initialize(blessed($instance))
+ ->get_meta_instance;
+
+ $meta_instance->set_slot_value($instance, $attr_name, $value);
+
+ if (ref $value && $self->is_weak_ref) {
+ $meta_instance->weaken_slot_value($instance, $attr_name);
+ }
+
+ if ($self->has_trigger) {
+ $self->trigger->($instance, $value, $self);
+ }
+}
+
+sub get_value {
+ my ($self, $instance) = @_;
+
+ if ($self->is_lazy) {
+ unless ($self->has_value($instance)) {
+ if ($self->has_default) {
+ my $default = $self->default($instance);
+ $self->set_value($instance, $default);
+ }
+ else {
+ $self->set_value($instance, undef);
+ }
+ }
+ }
+
+ if ($self->should_auto_deref) {
+
+ my $type_constraint = $self->type_constraint;
+
+ if ($type_constraint->is_a_type_of('ArrayRef')) {
+ my $rv = $self->SUPER::get_value($instance);
+ return unless defined $rv;
+ return wantarray ? @{ $rv } : $rv;
+ }
+ elsif ($type_constraint->is_a_type_of('HashRef')) {
+ my $rv = $self->SUPER::get_value($instance);
+ return unless defined $rv;
+ return wantarray ? %{ $rv } : $rv;
+ }
+ else {
+ confess "Can not auto de-reference the type constraint '" . $type_constraint->name . "'";
+ }
+
+ }
+ else {
+
+ return $self->SUPER::get_value($instance);
+ }
+}
## installing accessors
=item B<accessor_metaclass>
+=item B<get_value>
+
+=item B<set_value>
+
=back
=head2 Additional Moose features
use base 'Moose::Meta::Method',
'Class::MOP::Method::Accessor';
-## generators
+## Inline method generators
-sub generate_accessor_method {
+sub generate_accessor_method_inline {
my $self = shift;
my $attr = $self->associated_attribute;
my $attr_name = $attr->name;
return $sub;
}
-sub generate_writer_method {
+sub generate_writer_method_inline {
my $self = shift;
my $attr = $self->associated_attribute;
my $attr_name = $attr->name;
return $sub;
}
-sub generate_reader_method {
+sub generate_reader_method_inline {
my $self = shift;
my $attr = $self->associated_attribute;
my $attr_name = $attr->name;
return $sub;
}
-#sub generate_predicate_method {
-# my $self = shift;
-# my $attr = $self->associated_attribute;
-# my $attr_name = $attr->name;
-#}
-#
-#sub generate_clearer_method {
-# my $self = shift;
-# my $attr = $self->associated_attribute;
-# my $attr_name = $attr->name;
-#}
-
-## Inline methods
-
-*generate_accessor_method_inline = \&generate_accessor_method;
-*generate_reader_method_inline = \&generate_reader_method;
-*generate_writer_method_inline = \&generate_writer_method;
-#*generate_predicate_method_inline = \&generate_predicate_method;
-#*generate_clearer_method_inline = \&generate_clearer_method;
-
## ... private helpers
sub _inline_check_constraint {
use strict;
use warnings;
-use Test::More no_plan => 1;
+use Test::More tests => 1;
use Test::Exception;
BEGIN {
use_ok('Moose');
}
+
+=pod
+
+Nothing here yet, but soon :)
+
+=cut