use Carp 'confess';
use Scalar::Util 'blessed', 'weaken';
-our $VERSION = '0.87';
+our $VERSION = '0.90';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
sub immutable_options { %{ $_[0]{__immutable}{options} } }
-sub is_mutable {0}
-sub is_immutable {1}
+sub is_mutable { 0 }
+sub is_immutable { 1 }
+
+sub _immutable_metaclass { ref $_[1] }
sub superclasses {
- confess "This method is read-only" if @_ > 1;
- $_[0]->next::method;
+ my $orig = shift;
+ my $self = shift;
+ confess "This method is read-only" if @_;
+ $self->$orig;
}
sub _immutable_cannot_call {
Carp::confess "This method cannot be called on an immutable instance";
}
-sub add_method { shift->_immutable_cannot_call }
-sub alias_method { shift->_immutable_cannot_call }
-sub remove_method { shift->_immutable_cannot_call }
-sub add_attribute { shift->_immutable_cannot_call }
-sub remove_attribute { shift->_immutable_cannot_call }
-sub remove_package_symbol { shift->_immutable_cannot_call }
+sub add_method { _immutable_cannot_call() }
+sub alias_method { _immutable_cannot_call() }
+sub remove_method { _immutable_cannot_call() }
+sub add_attribute { _immutable_cannot_call() }
+sub remove_attribute { _immutable_cannot_call() }
+sub remove_package_symbol { _immutable_cannot_call() }
sub class_precedence_list {
- @{ $_[0]{__immutable}{class_precedence_list}
- ||= [ shift->next::method ] };
+ my $orig = shift;
+ my $self = shift;
+ @{ $self->{__immutable}{class_precedence_list}
+ ||= [ $self->$orig ] };
}
sub linearized_isa {
- @{ $_[0]{__immutable}{linearized_isa} ||= [ shift->next::method ] };
+ my $orig = shift;
+ my $self = shift;
+ @{ $self->{__immutable}{linearized_isa} ||= [ $self->$orig ] };
}
sub get_all_methods {
- @{ $_[0]{__immutable}{get_all_methods} ||= [ shift->next::method ] };
+ my $orig = shift;
+ my $self = shift;
+ @{ $self->{__immutable}{get_all_methods} ||= [ $self->$orig ] };
}
sub get_all_method_names {
- @{ $_[0]{__immutable}{get_all_method_names} ||= [ shift->next::method ] };
+ my $orig = shift;
+ my $self = shift;
+ @{ $self->{__immutable}{get_all_method_names} ||= [ $self->$orig ] };
}
sub get_all_attributes {
- @{ $_[0]{__immutable}{get_all_attributes} ||= [ shift->next::method ] };
+ my $orig = shift;
+ my $self = shift;
+ @{ $self->{__immutable}{get_all_attributes} ||= [ $self->$orig ] };
}
sub get_meta_instance {
- $_[0]{__immutable}{get_meta_instance} ||= shift->next::method;
+ my $orig = shift;
+ my $self = shift;
+ $self->{__immutable}{get_meta_instance} ||= $self->$orig;
}
sub get_method_map {
- $_[0]{__immutable}{get_method_map} ||= shift->next::method;
+ my $orig = shift;
+ my $self = shift;
+ $self->{__immutable}{get_method_map} ||= $self->$orig;
}
sub add_package_symbol {
+ my $orig = shift;
+ my $self = shift;
confess "Cannot add package symbols to an immutable metaclass"
- unless ( caller(1) )[3] eq 'Class::MOP::Package::get_package_symbol';
+ unless ( caller(3) )[3] eq 'Class::MOP::Package::get_package_symbol';
- shift->next::method(@_);
+ $self->$orig(@_);
}
1;