@@ -4,9 +4,9 @@ use Carp;
4
4
use warnings;
5
5
use strict;
6
6
our $AUTOLOAD ;
7
- our $VERSION = ' 1.02 ' ; # remember to update version in POD!
7
+ our $VERSION = ' 1.03 ' ; # remember to update version in POD!
8
8
# $DB::single=1;
9
-
9
+ my $debug = $ENV { DEBUG_ATTRIBUTE_HANDLERS } || 0;
10
10
my %symcache ;
11
11
sub findsym {
12
12
my ($pkg , $ref , $type ) = @_ ;
@@ -241,20 +241,33 @@ sub _apply_handler_AH_ {
241
241
my ($declaration , $phase ) = @_ ;
242
242
my ($pkg , $ref , $attr , $data , $raw , $handlerphase , $filename , $linenum ) = @$declaration ;
243
243
return unless $handlerphase -> {$phase };
244
- # print STDERR "Handling $attr on $ref in $phase with [$data]\n";
244
+ print STDERR " Handling $attr on $ref in $phase with [$data ]\n "
245
+ if $debug ;
245
246
my $type = ref $ref ;
246
247
my $handler = " _ATTR_${type} _${attr} " ;
247
248
my $sym = findsym($pkg , $ref );
248
249
$sym ||= $type eq ' CODE' ? ' ANON' : ' LEXICAL' ;
249
250
no warnings;
250
251
if (!$raw && defined ($data )) {
251
252
if ($data ne ' ' ) {
252
- my $evaled = eval (" package $pkg ; no warnings; no strict;
253
- local \$ SIG{__WARN__}=sub{die}; [$data ]" );
254
- $data = $evaled unless $@ ;
253
+ # keeping the minimum amount of code inside the eval string
254
+ # makes debugging perl internals issues with this logic easier.
255
+ my $code = " package $pkg ; my \$ ref= [$data ]; \$ data= \$ ref; 1" ;
256
+ print STDERR " Evaling: '$code '\n "
257
+ if $debug ;
258
+ local $SIG {__WARN__ } = sub{ die };
259
+ no strict;
260
+ no warnings;
261
+ # Note we do not need
262
+ eval ($code ) or do {
263
+ print STDERR " Eval failed: $@ "
264
+ if $debug ;
265
+ };
255
266
}
256
267
else { $data = undef }
257
268
}
269
+
270
+ # now call the handler with the $data decoded (maybe)
258
271
$pkg -> $handler ($sym ,
259
272
(ref $sym eq ' GLOB' ? *{$sym }{ref $ref }||$ref : $ref ),
260
273
$attr ,
@@ -300,7 +313,7 @@ Attribute::Handlers - Simpler definition of attribute handlers
300
313
301
314
=head1 VERSION
302
315
303
- This document describes version 1.02 of Attribute::Handlers.
316
+ This document describes version 1.03 of Attribute::Handlers.
304
317
305
318
=head1 SYNOPSIS
306
319
0 commit comments