Revision history for Perl extension Class-MOP.
+0.22
+ * Class::MOP::Class
+ - localized $@ in the *_package_variable functions
+ because otherwise, it does ugly things in Moose.
+ - added test case for this
+
0.21 Wed. March 15, 2006
* Class::MOP::Class
- fixed issue where metaclasses are reaped from
t/106_LazyClass_test.t
t/107_C3MethodDispatchOrder_test.t
t/200_Class_C3_compatibility.t
+t/300_random_eval_bug.t
t/pod.t
t/pod_coverage.t
t/lib/BinaryTree.pm
-Class::MOP version 0.21
+Class::MOP version 0.22
===========================
See the individual module documentation for more information
use Class::MOP::Attribute;
use Class::MOP::Method;
-our $VERSION = '0.21';
+our $VERSION = '0.22';
## ----------------------------------------------------------------------------
## Setting up our environment ...
use Sub::Name 'subname';
use B 'svref_2object';
-our $VERSION = '0.07';
+our $VERSION = '0.08';
# Self-introspection
*{$self->name . '::' . $name} = $initial_value;
}
else {
+ # NOTE:
+ # We HAVE to localize $@ or all
+ # hell breaks loose. It is not
+ # good, believe me, not good.
+ local $@;
eval $sigil . $self->name . '::' . $name;
confess "Could not create package variable ($variable) because : $@" if $@;
}
|| confess "variable name does not have a sigil";
my ($sigil, $name) = ($variable =~ /^(.)(.*)$/);
no strict 'refs';
- # try to fetch it first,.. see what happens
+ # NOTE:
+ # We HAVE to localize $@ or all
+ # hell breaks loose. It is not
+ # good, believe me, not good.
+ local $@;
my $ref = eval '\\' . $sigil . $self->name . '::' . $name;
confess "Could not get the package variable ($variable) because : $@" if $@;
# if we didn't die, then we can return it
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+BEGIN {
+ use_ok('Class::MOP');
+}
+
+=pod
+
+This tests a bug which is fixed in 0.22 by
+localizing all the $@'s around any evals.
+This a real pain to track down.
+
+Moral of the story:
+
+ ALWAYS localize your globals :)
+
+=cut
+
+{
+ package Company;
+ use strict;
+ use warnings;
+ use metaclass;
+
+ sub new {
+ my ($class) = @_;
+ return bless {} => $class;
+ }
+
+ sub employees {
+ die "This didnt work";
+ }
+
+ sub DESTROY {
+ my $self = shift;
+ foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) {
+ $method->{code}->($self);
+ }
+ }
+}
+
+eval {
+ my $c = Company->new();
+ $c->employees();
+};
+ok($@, '... we die correctly with bad args');
\ No newline at end of file