develooper Front page | perl.perl5.porters | Postings from November 2007

[PATCH] Attribute::Handlers till ears are bleeding

Thread Next
Michael G Schwern
November 18, 2007 16:20
[PATCH] Attribute::Handlers till ears are bleeding
Message ID:
Investigating the bleadperl failure of Exporter::Simple revealed that the "is
it a string or an array" attribute data guessing code isn't working properly,
or at least as documented, in 5.10.

The docs say...

    if &foo had been declared:

        sub foo :Loud("turn it up to 11, man!") {...}

    then the string "turn it up to 11, man!" would be passed as the last

And that works fine.  The problem comes later...

       Attribute::Handlers makes strenuous efforts to convert the data
       argument ($_[4]) to a useable form before passing it to the handler.
       For example, all of these:

          sub foo :Loud(till=>ears=>are=>bleeding) {...}
          sub foo :Loud(['till','ears','are','bleeding']) {...}
          sub foo :Loud(qw/till ears are bleeding/) {...}
          sub foo :Loud(qw/my, ears, are, bleeding/) {...}
          sub foo :Loud(till,ears,are,bleeding) {...}

       causes it to pass "['till','ears','are','bleeding']" as the
       handler's argument.

       However, if the data can't be parsed as valid Perl, then
       it is passed as an uninterpreted string. For example:
          sub foo :Loud(my,ears,are,bleeding) {...}
          sub foo :Loud(qw/my ears are bleeding) {...}
       cause the strings 'my,ears,are,bleeding' and 'qw/my ears are bleeding'

       respectively to be passed as the data argument.

In reality, bleadperl gets a bunch wrong.  This is a result of the strict patch.

    till=>ears=>are=>bleading           => string
    ['till','ears','are','bleeding']    => string
    till,ears,are,bleeding              => string

5.8.8 gets only one wrong.

    ['till','ears','are','bleeding']    => [['till','ears','are','bleeding']]

I'm going to assume that 5.8.8 one is a documentation mistake?  Confirm/deny?

To that end, here's a patch which fixes the strict bug in Attribute::Handlers
and encodes the previously broken "Loud" attribute data conversion examples as
tests.  I think this should go into 5.10.

You are wicked and wrong to have broken inside and peeked at the
implementation and then relied upon it.
	-- tchrist in <31832.969261130@chthon>

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About