Skip to content

Instantly share code, notes, and snippets.

@worr
Created October 15, 2011 22:44
Show Gist options
  • Select an option

  • Save worr/1290254 to your computer and use it in GitHub Desktop.

Select an option

Save worr/1290254 to your computer and use it in GitHub Desktop.
How immutable is immutable?
#!/usr/bin/env perl
use strict;
use warnings;
use v5.10;
use Class::MOP;
my $tc_meta = Class::MOP::Class->initialize("TestClass");
$tc_meta->make_immutable(inline_constructor => 0);
eval {
$tc_meta->add_method("cm_test", sub { say "Not so immutable" });
my $test1 = TestClass->new;
$test1->cm_test;
} or warn "Can not add method the Class::MOP way";
eval {
no strict 'refs';
*{"TestClass::of_test"} = sub { my $self = shift; say "Not so immutable" };
my $test2 = TestClass->new;
$test2->of_test;
use strict;
} or warn "Can not add method the old fashioned way";
package TestClass;
sub new {
return bless({}, shift);
}
@ironcamel

Copy link
Copy Markdown

When doing evals of the form eval { ... } or warn "blah" shouldn't you have a true value as the last expression in the eval block? Like so: eval { ...; 1; } or warn "blah"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment