Attributes::Handler in 5.8 vs. 5.10

ChrisDolan on 2008-07-29T05:26:30

If you use attributes with multiple arguments like so: sub foo : myattr(one, two) { }

then it's important to realize that the attribute arguments are parsed differently under Perl 5.8 vs. Perl 5.10. In 5.8, you get a string like "one, two" passed to your :ATTR sub. Under 5.10, you instead get an arrayref like ['one', 'two'].

I had some 5.8 code that parsed the attribute args like so: my @args = split /\s*,\s*/, $args which resulted in @args containing 'ARRAY[0x123456]' under 5.10! My new workaround that is compatible with 5.8 and 5.10 is: my @args = ref $args ? @{$args} : split /\s*,\s*/, $args;

If anyone sees flaws in this workaround, or has a better explanation, please comment.