From: Michael G. Schwern Date: Sun, 18 Nov 2007 16:20:31 +0000 (-0800) Subject: Attribute::Handlers till ears are bleeding X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f0eb64d5864dd24b27dde744ed11db1acc008d0;p=p5sagit%2Fp5-mst-13.2.git Attribute::Handlers till ears are bleeding Message-ID: <4740D6CF.6030407@pobox.com> p4raw-id: //depot/perl@32405 --- diff --git a/MANIFEST b/MANIFEST index 10743b2..b925ec5 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1437,6 +1437,7 @@ lib/Attribute/Handlers/demo/MyClass.pm Attribute::Handlers demo lib/Attribute/Handlers.pm Attribute::Handlers lib/Attribute/Handlers/README Attribute::Handlers lib/Attribute/Handlers/t/constants.t Test constants and Attribute::Handlers +lib/Attribute/Handlers/t/data_convert.t Test attribute data conversion lib/Attribute/Handlers/t/linerep.t See if Attribute::Handlers works lib/Attribute/Handlers/t/multi.t See if Attribute::Handlers works lib/attributes.pm For "sub foo : attrlist" diff --git a/lib/Attribute/Handlers.pm b/lib/Attribute/Handlers.pm index 6bd121b..ac3db28 100644 --- a/lib/Attribute/Handlers.pm +++ b/lib/Attribute/Handlers.pm @@ -4,7 +4,7 @@ use Carp; use warnings; use strict; use vars qw($VERSION $AUTOLOAD); -$VERSION = '0.78_06'; +$VERSION = '0.78_07'; # $DB::single=1; my %symcache; @@ -190,7 +190,7 @@ 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; + my $evaled = !$raw && eval("package $pkg; no warnings; no strict; local \$SIG{__WARN__}=sub{die}; [$data]"); $data = ($evaled && $data =~ /^\s*\[/) ? [$evaled] : ($evaled) ? $evaled diff --git a/lib/Attribute/Handlers/t/data_convert.t b/lib/Attribute/Handlers/t/data_convert.t new file mode 100644 index 0000000..56e66c4 --- /dev/null +++ b/lib/Attribute/Handlers/t/data_convert.t @@ -0,0 +1,54 @@ +#!/usr/bin/perl -w + +# Test attribute data conversion using examples from the docs + +BEGIN { + if ($ENV{PERL_CORE}) { + chdir 't' if -d 't'; + @INC = '../lib'; + } +} + +use Test::More tests => 8; + +package LoudDecl; +use Attribute::Handlers; + +sub Loud :ATTR { + my ($package, $symbol, $referent, $attr, $data, $phase) = @_; + + ::is_deeply( $data, $referent->(), *{$symbol}{NAME} ); +} + + +sub test1 :Loud(till=>ears=>are=>bleeding) { + [qw(till ears are bleeding)] +} + +sub test2 :Loud(['till','ears','are','bleeding']) { + [[qw(till ears are bleeding)]] +} + +sub test3 :Loud(qw/till ears are bleeding/) { + [qw(till ears are bleeding)] +} + +sub test4 :Loud(qw/my, ears, are, bleeding/) { + [('my,', 'ears,', 'are,', 'bleeding')] +} + +sub test5 :Loud(till,ears,are,bleeding) { + [qw(till ears are bleeding)] +} + +sub test6 :Loud(my,ears,are,bleeding) { + 'my,ears,are,bleeding'; +} + +sub test7 :Loud(qw/my ears are bleeding) { + 'qw/my ears are bleeding'; #' +} + +sub test8 :Loud("turn it up to 11, man!") { + 'turn it up to 11, man!'; +}