ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Strict.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Strict.pm (file contents):
Revision 1.29 by root, Thu Aug 18 17:58:53 2011 UTC vs.
Revision 1.30 by root, Thu Aug 18 19:35:15 2011 UTC

26 26
27use Carp qw(croak); 27use Carp qw(croak);
28 28
29use AnyEvent (); BEGIN { AnyEvent::common_sense } 29use AnyEvent (); BEGIN { AnyEvent::common_sense }
30 30
31AnyEvent::_isa_hook 1 => "AnyEvent::Strict", 1; 31AnyEvent::_isa_hook 0 => "AnyEvent::Strict", 1;
32 32
33my $magic = []; 33BEGIN {
34 34 if (defined &Internals::SvREADONLY) {
35sub wrap { 35 # readonly available (at least 5.8.9+, working better in 5.10.1+)
36 *wrap = sub {
36 my $cb = shift; 37 my $cb = shift;
37 38
38 sub { 39 sub {
40 Internals::SvREADONLY $_, 1;
41 &$cb;
42 Internals::SvREADONLY $_, 0;
43 }
44 };
45 } else {
46 # or not :/
47 my $magic = []; # a unique magic value
48
49 *wrap = sub {
50 my $cb = shift;
51
52 sub {
39 local $_ = $magic; 53 local $_ = $magic;
40 54
41 &$cb; 55 &$cb;
42 56
43 if (!ref $_ || $_ != $magic) { 57 if (!ref $_ || $_ != $magic) {
44 require AnyEvent::Debug; 58 require AnyEvent::Debug;
45 die "callback $cb (" . AnyEvent::Debug::cb2str ($cb) . ") modified \$_ without restoring it.\n"; 59 die "callback $cb (" . AnyEvent::Debug::cb2str ($cb) . ") modified \$_ without restoring it.\n";
60 }
61 }
46 } 62 };
47 } 63 }
48} 64}
49 65
50sub io { 66sub io {
51 my $class = shift; 67 my $class = shift;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines