Phoenix.pm: Attribute::Handlers and BEGIN blocks -- question(s)
Doug Miles
doug.miles at bpxinternet.com
Thu Dec 27 11:07:33 CST 2001
Shay Harding wrote:
> This got so long I'm going to post up top so you don't have to scroll...
>
> After some investigation it seems both of you are kind of correct. The
>
> $test : Test;
>
> was getting parsed before the BEGIN blocks, as it is checked at compile time
> since this is valid Perl syntax and is something I did not even know existed.
Thanks! I didn't know that was valid either.
> The ':' is used to set attributes for subroutines as 'locked' or 'method'.
>>From perldelta, perl 5.6:
>
> ---------------------------------------------------------
> New syntax for declaring subroutine attributes
>
> Formerly, if you wanted to mark a subroutine as being a method call or as
> requiring an automatic lock() when it is entered, you had to declare that
> with a `use attrs' pragma in the body of the subroutine. That can now be
> accomplished with declaration syntax, like this:
>
> sub mymethod : locked method ;
> ...
> sub mymethod : locked method {
> ...
> }
>
> sub othermethod :locked :method ;
> ...
> sub othermethod :locked :method {
> ...
> }
>
> (Note how only the first `:' is mandatory, and whitespace surrounding
> the `:' is optional.)
>
> AutoSplit.pm and SelfLoader.pm have been updated to keep the attributes with
> the stubs they provide. See the attributes manpage.
> --------------------------------------------------------------
>
>>From the attrs.pm pod:
>
> -----------------------------------------------------
> =head1 DESCRIPTION
>
> NOTE: Use of this pragma is deprecated. Use the syntax
>
> sub foo : locked method { }
>
> to declare attributes instead. See also L<attributes>.
>
> This pragma lets you set and get attributes for subroutines.
> Setting attributes takes place at compile time; trying to set
> invalid attribute names causes a compile-time error. Calling
> C<attrs::get> on a subroutine reference or name returns its list
> of attribute names. Notice that C<attrs::get> is not exported.
> ------------------------------------------------------
>
> So it seems these attributes were orignally entered in for use with threads.
> Learn something new everyday :)
>
> Attribute::Handlers seems to take this a step further and can be applied to
> subroutined, scalars, hashes, arrays, etc.
>
>
More information about the Phoenix-pm
mailing list