From: Sascha Blank Date: Sat, 8 Dec 2007 03:47:46 +0000 (-0800) Subject: [perl #48355] Handling of RAWDATA broken badly in Attribute::Handlers in perl 5.10... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b384a05d76a2022ec642d8bd7b87bb7147132641;p=p5sagit%2Fp5-mst-13.2.git [perl #48355] Handling of RAWDATA broken badly in Attribute::Handlers in perl 5.10.0 RC2 From: Sascha Blank (via RT) Message-ID: p4raw-id: //depot/perl@32598 --- diff --git a/lib/Attribute/Handlers.pm b/lib/Attribute/Handlers.pm index e035a14..6c7b3f5 100644 --- a/lib/Attribute/Handlers.pm +++ b/lib/Attribute/Handlers.pm @@ -190,9 +190,14 @@ sub _apply_handler_AH_ { my $sym = findsym($pkg, $ref); $sym ||= $type eq 'CODE' ? 'ANON' : 'LEXICAL'; no warnings; - my $evaled = !$raw && eval("package $pkg; no warnings; no strict; - local \$SIG{__WARN__}=sub{die}; [$data]"); - $data = $evaled unless $@; + if (!$raw && defined($data)) { + if ($data ne '') { + my $evaled = eval("package $pkg; no warnings; no strict; + local \$SIG{__WARN__}=sub{die}; [$data]"); + $data = $evaled unless $@; + } + else { $data = undef } + } $pkg->$handler($sym, (ref $sym eq 'GLOB' ? *{$sym}{ref $ref}||$ref : $ref), $attr, diff --git a/t/op/attrhand.t b/t/op/attrhand.t index fb8069f..8b11ac4 100644 --- a/t/op/attrhand.t +++ b/t/op/attrhand.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan tests => 1; +plan tests => 4; # test for bug #38475: parsing errors with multiline attributes @@ -22,6 +22,26 @@ sub WrongAttr :ATTR(CODE,RAWDATA) { ::ok(0); } +sub CheckData :ATTR(RAWDATA) { + # check that the $data element contains the given attribute parameters. + + if ($_[4] eq "12, 14") { + ::ok(1) + } + else { + ::ok(0) + } +} + +sub CheckEmptyValue :ATTR() { + if (not defined $_[4]) { + ::ok(1) + } + else { + ::ok(0) + } +} + package Deer; use base 'Antler'; @@ -35,3 +55,8 @@ sub something : TypeCheck( } something(); + +sub c :CheckData(12, 14) {}; + +sub d1 :CheckEmptyValue() {}; +sub d2 :CheckEmptyValue {};