develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24118] AutoReply: attribute bug on 'our' in Attribute::Handlers

Thread Next
Jos I. Boumans
October 5, 2003 04:14
Re: [perl #24118] AutoReply: attribute bug on 'our' in Attribute::Handlers
Message ID:
> the 'my' variable will correctly take the attribute, but the 'our' will
> not and give the following error:
> 	Invalid SCALAR attribute: watch at line 7
> A quick debug run shows that it breaks due to some @ISA oddness:
>  	# OK:
> 	perl -MAttribute::Handlers -e'sub a:ATTR(SCALAR){1};our$x:a'
> 	perl -MAttribute::Handlers -e'@ISA='b';sub b::a:ATTR(SCALAR);my$x:a'
> 	# BREAKS:
> 	perl -MAttribute::Handlers -e'@ISA='b';sub b::a:ATTR(SCALAR);our$x:a'
> 		Invalid SCALAR attribute: a at -e line 1
> 		BEGIN failed--compilation aborted at -e line 1.
After looking a bit further, it shows that attributes on 'our' are
resolved at compile time, and 'my' attributes are resolved at run time.
From perldoc attributes:
	Variable attributes in "our" declarations are also
       applied at compile time.  However, "my" variables get
       their attributes applied at run-time.

So for the first part of this bug report, it was my expectation being
wrong, and not a bug... however, it does make me wonder why the behaviour
of our vs my is different...

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