return;
}
+my $generate_class_accessor = sub {
+ my($name) = @_;
+ return sub {
+ my $self = shift;
+ if(@_) {
+ return $self->{$name} = shift;
+ }
+
+ foreach my $class($self->linearized_isa) {
+ my $meta = Mouse::Util::get_metaclass_by_name($class)
+ or next;
+
+ if(exists $meta->{$name}) {
+ return $meta->{$name};
+ }
+ }
+ return undef;
+ };
+};
+
+
package Mouse::Meta::Class;
use Mouse::Meta::Method::Constructor;
sub is_immutable { $_[0]->{is_immutable} }
-sub strict_constructor{
- my $self = shift;
- if(@_) {
- $self->{strict_constructor} = shift;
- }
-
- foreach my $class($self->linearized_isa) {
- my $meta = Mouse::Util::get_metaclass_by_name($class)
- or next;
-
- if(exists $meta->{strict_constructor}) {
- return $meta->{strict_constructor};
- }
- }
-
- return 0; # false
-}
+Mouse::Util::install_subroutines(__PACKAGE__,
+ strict_constructor => $generate_class_accessor->('strict_constructor'),
+);
sub _report_unknown_args {
my($metaclass, $attrs, $args) = @_;
return @{ $self->{after_method_modifiers}{$method_name} ||= [] }
}
+sub add_metaclass_accessor { # for meta roles (a.k.a. traits)
+ my($meta, $name) = @_;
+ $meta->add_method($name => $generate_class_accessor->($name));
+ return;
+}
+
package Mouse::Meta::Attribute;
require Mouse::Meta::Method::Accessor;
use overload
'""' => '_as_string',
- '0=' => '_identity',
+ '0+' => '_identity',
'|' => '_unite',
fallback => 1;
(void)set_slot(methods, name, code); /* $self->{methods}{$name} = $code */
}
-void
-add_class_accessor(SV* self, SV* name)
-CODE:
-{
- SV* const klass = mouse_call0(self, mouse_name);
- const char* fq_name = form("%"SVf"::%"SVf, klass, name);
- STRLEN keylen;
- const char* const key = SvPV_const(name, keylen);
- mouse_simple_accessor_generate(aTHX_ fq_name, key, keylen,
- XS_Mouse_inheritable_class_accessor, NULL, 0);
-}
-
MODULE = Mouse PACKAGE = Mouse::Meta::Class
BOOT:
}
}
+void
+add_metaclass_accessor(SV* self, SV* name)
+CODE:
+{
+ SV* const klass = mouse_call0(self, mouse_name);
+ const char* fq_name = form("%"SVf"::%"SVf, klass, name);
+ STRLEN keylen;
+ const char* const key = SvPV_const(name, keylen);
+ mouse_simple_accessor_generate(aTHX_ fq_name, key, keylen,
+ XS_Mouse_inheritable_class_accessor, NULL, 0);
+}
+
MODULE = Mouse PACKAGE = Mouse::Object
void