【发布时间】:2012-01-17 08:46:33
【问题描述】:
我根本不了解 Perl 子例程属性。
我从未在实际代码中见过它们,perldoc perlsub 和 perldoc attributes 无法回答我的问题:
- 属性有什么用?
- 他们带来了 Perl 最佳实践中尚未出现的哪些内容?
- 是否有任何使用属性的 CPAN 模块(众所周知的或其他的)?
如果有人能整理出一个详细的属性示例,说明它们应该如何使用,那就太好了。
对于像我一样一无所知的人,属性是下面attributes SYNOPSIS示例中冒号后面的参数:
sub foo : method ;
my ($x,@y,%z) : Bent = 1;
my $s = sub : method { ... };
use attributes (); # optional, to get subroutine declarations
my @attrlist = attributes::get(\&foo);
use attributes 'get'; # import the attributes::get subroutine
my @attrlist = get \&foo;
【问题讨论】:
-
Catalyst Web 框架使用属性。
-
mod_perl使用属性来区分method and non-method 处理程序。
标签: perl subroutine