attrs
. This pragma made it possible to hang a pair of built-in attributes on the function, for which it was necessary to specify use attrs
with the appropriate parameters inside this function. True, in March 2000 in Perl 5.6 this pragma was declared deprecated. It was replaced by the attributes
module, as well as an extended syntax for declaring variables / functions. It became possible to create their own labels for them and enter handlers for these labels. For unknown reasons, the popularity of the attributes did not receive. It's a pity.my $myVar : myAttribute = 10;
sub mySub : myAttribute1 : myAttribute2 {:}
Attribute::Util
. Lives on CPAN. I will not comment on the possibility of their use in real projects, but as a simple and graphic illustration it is what you need.Attribute::Abstract
, offers a substitute for the classic description of abstract methods. Pay attention to it if you have similar ads:sub myMethod { die "Abstract method called!"; }
sub myMethod: Abstract;
Attribute::Memoize
, allows you to add caching to functions that return a constant result for the same sets of arguments. Of course, it’s not difficult to wrap the function code in the if
block, but again, you can simply mark the function with an attribute :Memoize
and know that its result is cached.Attribute::Method
, allows you to get rid of writing the first line of almost any method:my $self = shift;
:Method
, and $self
appears by itself. In addition, you can specify which arguments are passed to the method - then they will also be initialized:sub myMethod :Method($x) { print "self=$self, x=$x\n" }
Source: https://habr.com/ru/post/53451/
All Articles